![]() |
|
[Release] Round float value - Printable Version +- ItsMods (https://www.itsmods.com) +-- Forum: Archive (https://www.itsmods.com/Forum-Archive.html) +--- Forum: Archive (https://www.itsmods.com/Forum-Archive--64.html) +--- Thread: [Release] Round float value (/Thread-Release-Round-float-value.html) |
Round float value - master131 - 09-02-2011 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); RE: Round float value - Justin - 09-03-2011 Does the function float() even exist? Thereby roundFloat(1.225, 2) returns 1.22 . RE: Round float value - BrokenSilenceDev - 09-03-2011 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. RE: Round float value - master131 - 09-04-2011 Well where ever you need to use it. -.- RE: Round float value - sirmodsalot - 09-07-2011 nice work thanks you very much
RE: Round float value - dafiz - 09-24-2011 How do I do this? :S |