如何使用 jquery 汇总不同类型的货币?我想做的是;
10.30 → 10 //Below .5 will round down
10.60 → 11 //After .5 will round up
849.95 → 850
1,022.20 → 1022
最佳答案
您可以使用Math.round()
The
Math.round()
function returns the value of a number rounded to the nearest integer.
请注意:带逗号的数字是字符串,您必须删除逗号。然后你可以使用 Number()
将其转换回数字,最后实现 Math.round()
console.log(Math.round(10.30));// → 10 //Below .5 will round down
console.log(Math.round(10.60))// → 11 //After .5 will round up
console.log(Math.round(849.95));// → 850
console.log(Math.round(Number('1,022.20'.replace(/,/g, ''))));// → 1022
关于javascript - 如何使用 Jquery 对货币进行四舍五入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59344580/