[Solved] Rounding Floating Point Values

Started by KamikazeHighland, Tue 03/01/2012 00:38:08

Previous topic - Next topic

KamikazeHighland

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.

monkey0506

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:

Code: ags
// Script.ash

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

// Script.asc

float RoundFloat(float value, RoundDirection dir)
{
  return IntToFloat(FloatToInt(value, dir));
}


SMF spam blocked by CleanTalk