gpt4 book ai didi

javascript - 美元金额的上限

转载 作者:可可西里 更新时间:2023-11-01 02:14:17 25 4
gpt4 key购买 nike

所以我在 javascript 中添加和减去 float ,我需要知道如何始终取小数点后 3 位以上的任何数字的上限。例如:

3.19 = 3.19

3.191 = 3.20

3.00000001 = 3.01

最佳答案

num = Math.ceil(num * 100) / 100;

不过,due to the way floats are represented ,您可能无法获得精确到小数点后两位的干净数字。出于显示目的,始终执行 num.toFixed(2)

关于javascript - 美元金额的上限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4817296/

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