09-02-2011, 13:56
This simple function(s) will round a float value to how many decimal places you want:
Usage:
roundFloat(1.225, 2); //Would return 1.23
And if your wondering how to round a float to the nearest whole number, just use:
int(123.456);
Code:
roundFloat(floatValue, places)
{
expValue = exponent(10, places);
floatValue *= expValue;
floatValue = int(floatValue);
floatValue /= expValue;
return float(floatValue);
}
exponent(basev, exp)
{
result = 1;
for(i = 0; i < exp; i++)
result *= basev;
return result;
}Usage:
roundFloat(1.225, 2); //Would return 1.23
And if your wondering how to round a float to the nearest whole number, just use:
int(123.456);
![[Image: 30xhrep.png]](http://i48.tinypic.com/30xhrep.png)
A casual conversation between barata and I about Nukem.



![[Image: 1314387173_broken.png]](http://team-ex.de/imagehosting/daten/1314387173_broken.png)
![[Image: classic-76561198035631049.png]](http://steamsignature.com/classic-76561198035631049.png)