我有一堆数字,例如 797.3333333333334
、852.22222111
、933.111023
,我总是想四舍五入到最接近的一分钱,这样我已经提到的数字将分别是 797.34
、852.23
、933.12
。
我说的是最接近的一分钱,但你也可以称它为最接近的十分之一。
有一个上限函数,但它只舍入到最接近的整数,Math.round()
最佳答案
The Math.ceil(x) function returns the smallest integer greater than or equal to a number "x".
var rounded = Math.ceil(yourNumber * 100)/100;
关于javascript - 如何始终将数字四舍五入到 Javascript 中最接近的一分钱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27083235/