function toFix(data, val) {
var numbers = ‘‘;
for (var i = 0; i < val; i++) {
numbers += ‘0‘;
}
var s = 1 + numbers;
var spot = "." + numbers;
var value = Math.round(parseFloat(data) * s) / s;
var d = value.toString().split(".");
if (d.length == 1) {
value = value.toString() + spot;
return value;
}
if (d.length > 1) {
if (d[1].length < 2) {
value = value.toString() + "0";
}
return value;
}
}
原文地址:https://www.cnblogs.com/wang-xx/p/11753689.html
时间: 2024-09-30 07:03:20