[Solved] Approximate a number

Status
Not open for further replies.
Level 6
Joined
Jun 4, 2017
Messages
172
How to approximate a number? I have an integer variable which has a random value each X time and I need that value to be approximate. For example the random value is 8 I want it to be approximate to 10, is there some function that could solve this problem?
 
Use (x/10)*10. This works, because it's an integer, so:
8/10 = 0.8
0.8 => 0, because integer
0*10=0

use ((x+5)/10)*10 if you want to approximate to the closest multiple of 10 or ((x+9)/10)*10 if you want to round up.
Oh I see, I would never have come to this solution alone, thank you it works perfectly :)
 
Status
Not open for further replies.
Back
Top