function changeTwoDecimal(x) {
if (x == "Infinity") {
return;
}
var f_x = parseFloat(x);
if (isNaN(f_x)) {
return
} else {
var f_x = Math.round(x * 100) / 100;
var s_x = f_x.toString();
var pos_decimal = s_x.indexOf('.');
if (pos_decimal < 0) {
pos_decimal = s_x.length;
s_x += '.';
}
while (s_x.length <= pos_decimal + 2) {
s_x += '0';
}
return s_x;
}
}
js保留2位小数 3.14159 =3.14
最新推荐文章于 2023-02-24 16:36:42 发布