Game Development Community

rounding numbers in script?

by Van der planken Roel · in Technical Issues · 09/19/2002 (2:48 pm) · 3 replies

how can I round a number so it there is no comma in it..


%obj.getDataBlock().maxDamage - %obj.getDamageLevel()

the result of this calculation can be somthing like 75.42 but I would like that it is rounde to 75

#1
09/19/2002 (5:48 pm)
I don't know, but have you looked in the Torque script reference document?

Edit: Here's the document link:

www.garagegames.com/downloads/TGE_Console_Cmds.rtf
#2
09/19/2002 (8:40 pm)
mfloor(%number) rounds down
mceil(%number) rounds up

:)
#3
09/20/2002 (10:28 am)
Or for your more traditional rounding function, you can use the following:

function mRound(%num)
{

    if ((%num-mFloor(%num) >= 0.5)
    {
        %value = mCeil(%num);
    }
    else
    {
        %value = mFloor(%num);
    }    

return %value;
}

You would then just use:

%val = mRound(74.52);