Blockland Forums
Home
Help
Login
Register
Blockland Forums
»
Blockland Forums
»
Modification Help
»
round to nearest integer?
« previous
next »
Print
Pages: [
1
]
Author
Topic: round to nearest integer? (Read 628 times)
Jorgur
July 04, 2011, 10:19:58 AM
round to nearest integer?
«
Last Edit: July 04, 2011, 08:44:36 PM by Badspot
»
Ad Bot
Advertisement
Nexus
July 04, 2011, 10:23:04 AM
mFloor()
it will always round down
Jorgur
July 04, 2011, 10:27:22 AM
And mCeil will always round up. However, I need the
nearest
integer.
Nexus
July 04, 2011, 10:46:58 AM
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.
Jorgur
July 04, 2011, 10:54:13 AM
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. :\
Chrono
July 04, 2011, 02:47:08 PM
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.
Print
Pages: [
1
]
« previous
next »
Blockland Forums
»
Blockland Forums
»
Modification Help
»
round to nearest integer?