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

 

 
posted @ 2019-08-20 20:11  日光之下无新事  阅读(272)  评论(0编辑  收藏  举报