Thursday, July 28, 2011

Useful javascript function: Math.round() with precision

Math._round = Math.round;

Math.round = function(number, precision)
{
    precision = Math.abs(parseInt(precision)) || 0;
    var coefficient = Math.pow(10, precision);
    return Math._round(number*coefficient)/coefficient;
}

No comments:

Post a Comment