JS - 保留小数点后2位

将浮点数四舍五入,保留小数点后2位。

Math.round(1.234*100) / 100
1.23
Math.round(1.235*100) / 100
1.24

如果需要百分比的话,去掉除以100即可。

Math.round(0.235*100)
24

即为24%。

猜你喜欢

转载自blog.csdn.net/seaalan/article/details/89017884