Author Topic: round to nearest integer?  (Read 627 times)

round to nearest integer?
« Last Edit: July 04, 2011, 08:44:36 PM by Badspot »

mFloor()

it will always round down

And mCeil will always round up. However, I need the nearest integer.

function mRound(%x)
{
   if(mFloor(%x) > (%x - 0.5))
      return mFloor(%x);
   else if(mCeil(%x) <= (%x - 0.5))
      return mCeil(%x);
   else
      return false;
}

I dunno, be creative.

I figured it out:

         if(%hp - mFloor(%hp) < 0.5) %client.RPData.value["hp"] = mFloor(%hp);
         else %client.RPData.value["hp"] = mCeil(%hp);

But too bad Blockland doesn't have a function for it. :\

Or just do this:

mFloatLength(%hp,0);

Though for something like HP, you should mFloor for max HP, mCeil for current HP.



Also don't break rule 1.