round off

Started by spook1, Mon 01/09/2003 20:46:50

Previous topic - Next topic

spook1

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 ;_))

Pumaman

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.

Archangel (aka SoupDragon)

Or, we just wait until CJ implements floating point numbers in ags, ISN'T THAT RIGHT CJ

^_^ <-- angelic look

Pumaman

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.

SMF spam blocked by CleanTalk