gpt4 book ai didi

javascript - 将数字四舍五入到恰好两位小数以进行货币格式设置

转载 作者:数据小太阳 更新时间:2023-10-29 03:59:50 24 4
gpt4 key购买 nike

我需要将货币四舍五入到小数点后两位。

两者

Math.round(num*Math.pow(10,2))/Math.pow(10,2)

Math.round(num*Math.pow(10,2))/Math.pow(10,2)

工作,除了它会删除任何尾随零,所以我得到 29.9 而不是 29.90

解决这个问题的最佳方法是什么?

最佳答案

您可以将此添加到您要设置特定格式的数字

.toFixed(2)

关于javascript - 将数字四舍五入到恰好两位小数以进行货币格式设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12402273/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com