• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[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?
 
Level 6
Joined
Jun 4, 2017
Messages
172
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.
Top