Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: spook1 on Mon 01/09/2003 20:46:50

Title: round off
Post by: spook1 on Mon 01/09/2003 20:46:50
Can anyone help me rounding numbers?

I have a plugin that solves linear equations, in order to solve kirchoffs laws in an electronic simulation game.
It calculates the voltage output in microVolts. I want to display the voltage in two digits, but AGS does not seem to round off the numbers.

449800 / 100000 = 44 according to AGS. I would like it to read 45 in this case.
Actually I would love to print 4,5. Can this be done?

kind regards,
Martijn (back from a long summerholiday ;_))
Title: Re:round off
Post by: Pumaman on Mon 01/09/2003 21:32:54
In order to round the number, you have to do the old trick:

(449800 + 50000) / 100000

Since AGS always rounds down, this change makes the result into a properly rounded number.

It would be possible to calculate the first decimal place as well, but you'd have to do a bit of maths with it to subtract the rounded value from the original value, then divide by 10000 or whatever.
Title: Re:round off
Post by: Archangel (aka SoupDragon) on Mon 01/09/2003 21:40:44
Or, we just wait until CJ implements floating point numbers in ags, ISN'T THAT RIGHT CJ

^_^ <-- angelic look
Title: Re:round off
Post by: Pumaman on Mon 01/09/2003 21:58:21
Quote from: Archangel on Mon 01/09/2003 21:40:44
Or, we just wait until CJ implements floating point numbers in ags, ISN'T THAT RIGHT CJ

:P

Actually floating point numbers in themselves aren't so difficult - it's the conversions between floating point numbers and integers that cause the headaches.