gpt4 book ai didi

actionscript-3 - 如何让数字具有 0.05 的精度?

转载 作者:行者123 更新时间:2023-12-03 22:43:04 25 4
gpt4 key购买 nike

以下内容将确保任何大数字仅精确到百分之一(related to this answer):

public function round( sc:Number ):Number
{
sc = sc * 100;
sc = Math.floor( sc );
sc = sc / 100;

return sc;
}

将我的数字四舍五入到 0.05 精度的最佳方法是什么?有什么聪明的方法可以通过位移来获得这个结果吗?例如,我想:

3.4566 = 3.45

3.04232 = 3.05

3.09 = 3.1

3.32 = 3.3

最佳答案

你可以乘以 20,四舍五入,然后除以 20。

编辑:您将需要使用 Math.round() 而不是 Math.floor(),否则您的测试用例 3.09 将变成 3.05。

关于actionscript-3 - 如何让数字具有 0.05 的精度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/799598/

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