如何使用Jquery进行货币舍入[重复]

问题描述 投票:0回答:2

如何使用jquery汇总不同类型的货币?我想做的是;

10.30 → 10 //Below .5 will round down
10.60 → 11 //After .5 will round up
849.95 → 850
1,022.20 → 1022
javascript jquery math currency
2个回答
3
投票

您可以使用Math.round()

Math.round()函数返回舍入到最接近整数的数字的值。

请注意:带有逗号的数字是一个字符串,您必须删除逗号。然后,您可以使用Math.round()将其转换回数字,最后实现Math.round()

Number()

0
投票

或者您可以使用jquery插件:Math.round()然后就这么简单:

Math.round()
© www.soinside.com 2019 - 2024. All rights reserved.