Author Topic: [Resource] Rounding Float Numbers  (Read 834 times)

I made this quickly and wasn't sure if other people needed it so I will post it here

Code: [Select]
function mFloat(%val)
{
%dec = strPos(%val,".");
if(%dec == -1)
return %val;
%tenth = getSubStr(%val,%dec+1,1);
if(%tenth >= 5)
return mCeil(%val);
else
return mFloor(%val);
}
This will return the same value if there is no decimals or return whatever integer is closest to it.

If anyone has a different way or better way of doing it, post here.

Code: [Select]
function mRound(%float)
{
     return mFloor(%float + 0.5);
}

???

Haha wow, now that I think of it I feel a little silly

I remember doing something similar to this at one point, except I did some kind of odd thing that didn't work anyway, haha.

A much better resource would be one that can round to a given interval with an optional offset

Code: [Select]
function mRound(%value)
{
        return mFloatLength(%value, 0);
}

??

Code: [Select]
function mRound(%value)
{
        return mFloatLength(%value, 0);
}

??
wouldn't that just remove decimals and not actually do any rounding or would torque do some weird thing and make it round automatically

wouldn't that just remove decimals and not actually do any rounding or would torque do some weird thing and make it round automatically

mFloatLength includes a rounding operation. mFloatLength(6.59, 0) returns 7.

mFloatLength includes a rounding operation.
sounds like one bit of information that will be useful in the future

sounds like that could potentially break something i might make, but i don't know what or how