首页
Python
Java
PHP
IOS
NodeJS
JavaScript
HTML5
小程序
AI
如有
全部标签
javascript - 如有必要,如何舍入至多 2 位小数
我希望最多四舍五入小数点后两位,但仅在必要时进行。输入:101.77777779.1输出:101.789.1如何在JavaScript中做到这一点? 最佳答案 使用Math.round():Math.round(num*100)/100或者更具体地说,为了确保1.005等值正确舍入,请使用Number.EPSILON:Math.round((num+Number.EPSILON)*100)/100 关于javascript-如有必要,如何舍入至多2位小数,我们在StackOverflow
至多
javascript
section
code
pre
rounding
decimal-point
1
2
Home
Powered By IT.CAOLU.XIN
页面耗时:0.0517s