Sporkinator icon

Round(x)

Sporkinator | PRO | 12/21/11 12:31:45 AM UTC | 0 ⭐ | 283 👁️ | Never ⏰ | []
Game Maker |

0 B

|

None

|

0 👍

/

0 👎

/*  round() without the loss of accuracy with huge numbers
    
    Test code:
    
    show_message(round(600851475143)); //WRONG
    show_message(Round(600851475143)); //RIGHT
    
    This script also avoids the GM bug where round(0.5) = 0
    Now, Round(0.5) = 1 like it should.
*/
var frc;
frc = frac(argument0);
if (frc >= 0.5)
    return argument0 - frc + 1;
else if (frc <= -0.5)
    return argument0 - frc - 1;
else
    return argument0 - frc;

Comments