码迷,mamicode.com
首页 > 编程语言 > 详细

javascript Round Function

时间:2019-08-20 20:35:23      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:pretty   script   var   javascrip   multi   math   dig   one   tip   


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

 

 

javascript Round Function

标签:pretty   script   var   javascrip   multi   math   dig   one   tip   

原文地址:https://www.cnblogs.com/sipher/p/11385290.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!