javascript Round Function


var rounded = Math.round( number * 10 ) / 10;   // round to one digit
var rounded = Math.round( number * 100 ) / 100;   // round to two digit
function round(value, precision) {
    var multiplier = Math.pow(10, precision || 0);
    return Math.round(value * multiplier) / multiplier;
}

var fixed = rounded.toFixed(1);  // round to one digit
var fixed = rounded.toFixed(2); // round to two digit
 
原文地址:https://www.cnblogs.com/sipher/p/11385290.html