Reputation: 74
Can anyone explain this?
what am I doing wrong?
Upvotes: 0
Views: 7734
Reputation: 1569
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:
Also you can see this SO question:
Very strange number operation issue
Hope this helps.
Upvotes: 3
Reputation: 16518
Round is doing the correct thing. 0.285 cannot be exactly represented as a binary floating point value. As you see, when multiplied by 100 it approximates to 28.4999999... which is less than 28.5, so the value is rounded down.
Upvotes: 4