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?
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?
About the author
#2
08/02/2004 (12:27 pm)
MFloor ??? what does this do?
#3
Ceiling(x) is the smallest integer >= x
08/02/2004 (12:36 pm)
Floor(x) is the largest integer that is <= xCeiling(x) is the smallest integer >= x
#4
"how do i drop the .00 and make it a int of sorts in script?"
*shrugs*
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*
#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
function mRound(%val)
{
if ((%val-mFloor(%val)) < 0.5)
%ret = mFloor(%val;
else
%ret = mCeil(%vail);
return %ret;
}
08/04/2004 (2:32 pm)
I prefer to write an mRound functionfunction mRound(%val)
{
if ((%val-mFloor(%val)) < 0.5)
%ret = mFloor(%val;
else
%ret = mCeil(%vail);
return %ret;
}
Torque Owner Harold "LabRat" Brown