Math.round()错误的计算在AS3? [英] Math.round() wrong calculation in as3?

查看:201
本文介绍了Math.round()错误的计算在AS3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释一下吗?

我是什么做错了吗?

推荐答案

Math.Round(X:编号)x舍入到最近的整数值。在你的情况下,28是28.499999999999996最接近的整数值。因此,这里的行为是正确的。什么是奇怪的是,0.285 * 100不是28.5,但毕竟是在AS3 Number类的precision的结果。下面是关于这一点,多一点信息,可能的解决方案:

Math.Round(x:Number) rounds x to the nearest integer value. In your case 28 is the nearest integer value for 28.499999999999996. So here the behavior is correct. What is weird is that 0.285 * 100 is not 28.5, but that is a consequence of the precision of the Number class in as3. Here is a little more information about this and a possible solution:

Innacurate数学成绩

另外可以看到此等问题:

Also you can see this SO question:

<一个href="http://stackoverflow.com/questions/6154651/flex-as3-very-strange-simple-number-operation-issue">Very陌生号码的操作问题

希望这有助于。

这篇关于Math.round()错误的计算在AS3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆