15.8.2.15 Math.round(x)

2010-07-12

number Math.round(x:number|mixed)

Round x and return it. If the first decimal is 5 or higher, round acts like ceil. Otherwise round acts like floor.

Code: (Meta Ecma)
Math.round = function(x){
x = ToNumber(x);
if (isNaN(x)) return NaN;
if (x === +0) return +0;
if (x === -0) return -0;
if (x === +Infinity) return +Infinity;
if (x === -Infinity) return -Infinity;
if (x > 0 && x < 0.5) return +0;
if (x < 0 && x >= -0.5) return -0;
return Math.round(x);
// if (x-Math.floor(x)<0.5) return Math.floor(x); else return Math.ceil(x);
}