Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: KamikazeHighland on Tue 03/01/2012 00:38:08

Title: [Solved] Rounding Floating Point Values
Post by: KamikazeHighland on Tue 03/01/2012 00:38:08
Is there a way or method to round floating point values without converting them to integers?  Other than by doing this:

IntToFloat(FloatToInt(var1, eRoundUp))

Unless this isn't inefficient, or if it's the most efficient way.  This is rounding the float value and then using it again in a function.
Title: Re: Rounding Floating Point Values
Post by: monkey0506 on Tue 03/01/2012 02:17:38
I can't imagine that AGS would be performing a data type conversion inefficiently. And seeing as there's no other way to strip out the whole number part of a floating-point number in AGS, then I don't see any way of doing it more efficiently. If you really wanted to simplify your own code:

// Script.ash

import float RoundFloat(float value, RoundDirection=eRoundNearest);

// Script.asc

float RoundFloat(float value, RoundDirection dir)
{
  return IntToFloat(FloatToInt(value, dir));
}
Title: Re: Rounding Floating Point Values
Post by: KamikazeHighland on Tue 03/01/2012 02:27:19
Awesome, thanks!