HelpRound up float value

Posts 1–4 of 4 · Page 1 of 1
Round up float value
Hey,
is there a way to round up a float value? The internal function doesnt work for some reason. I want to round up a KD-ratio
I don't have much knowledge about exactly this, but I'm pretty sure that if a function is supposed to work and it doesn't, you have done something wrong. It's editing in notepad we're talking about here, and the "rules" apply, no matter what operating system you use, or whether you have steam or aiw version.
Okay i got it working. The next problem is, that it return an integer, but i want a float value (from 1.5777778 to 1.57)
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

Spent ages using a string approach when it's so easy to do it mathematically. I'm so stupid :3
Posts 1–4 of 4 · Page 1 of 1
This thread is closed for replies.

Tags for this Thread

None

Talk with us