Game Development Community

INT rounding problem ... IM LOST!

by Bryce Kaminsky · in General Discussion · 08/02/2004 (12:13 pm) · 7 replies

Im doing rounding code to get the number out of a larger number

like ....
242
i want 2 then 4 then 2
so i 242/100 get 2.42 <<<---- how do i drop the .00 and make it a int of sorts in script?

#1
08/02/2004 (12:14 pm)
%var = mFloor(2.42);
#2
08/02/2004 (12:27 pm)
MFloor ??? what does this do?
#3
08/02/2004 (12:36 pm)
Floor(x) is the largest integer that is <= x
Ceiling(x) is the smallest integer >= x
#4
08/02/2004 (12:38 pm)
What you asked

"how do i drop the .00 and make it a int of sorts in script?"

*shrugs*
#5
08/03/2004 (2:07 am)
MFloor(2.42) would return 2
mCeil(2.42) would return 3
#6
08/04/2004 (11:03 am)
You may want to consider adding 0.5 (or subtracting 0.5 for negative numbers) prior to a MFloor call. This is a widely used method to "round" the number to the closest INT.
#7
08/04/2004 (2:32 pm)
I prefer to write an mRound function

function mRound(%val)
{
if ((%val-mFloor(%val)) < 0.5)
%ret = mFloor(%val;
else
%ret = mCeil(%vail);

return %ret;
}