0

Can anyone explain this?

enter image description here

what am I doing wrong?

mauris
  • 42,982
  • 15
  • 99
  • 131
Arafat
  • 74
  • 1
  • 8

2 Answers2

4

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.

Devon_C_Miller
  • 16,248
  • 3
  • 45
  • 71
3

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 math results

Also you can see this SO question:

Very strange number operation issue

Hope this helps.

Community
  • 1
  • 1
Diego
  • 1,531
  • 1
  • 15
  • 27