作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
以下内容将确保任何大数字仅精确到百分之一(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/
我是一名优秀的程序员,十分优秀!