ItsMods

Full Version: Round float value
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This simple function(s) will round a float value to how many decimal places you want:

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);
Does the function float() even exist? Thereby roundFloat(1.225, 2) returns 1.22 .
Dont those functions need to be declared in some way?
How?
Where do you put that piece of code to make it round to a whole number.
Well where ever you need to use it. -.-
nice work thanks you very much Superman
How do I do this? :S