0

I found that in Actionscript2, if Math.round does work when I do Math.round(7.5) and it gives me 8, but if I have an math expression which has a value 7.5 and apply Math.round to it, like: Math.round(value * 10) (here value is 0.75), instead of giving me 8, it gives me 7

Anyone know what exactly happened to it?

Thanks in advance!

Alan
  • 178
  • 1
  • 10
  • 1
    This sounds like a floating-point arithmetic problem. – elixenide Mar 12 '14 at 02:08
  • @EdCottrell yes, I just don't know why it works with a number but fails with a math expression.. – Alan Mar 12 '14 at 02:44
  • @DeveloperGuo Thanks for the link, but this is what I am trying to do - rounding to 1 decimal point. The function `toFixed` doesn't exist in Actionscript2. – Alan Mar 12 '14 at 02:48

2 Answers2

0
function test(val:Number):int {
  return Util.print(Math.round(val * 10));;
}   
test(.75);   //prints 8

Perhaps provide your code?

DeveloperGuo
  • 636
  • 5
  • 15
  • thanks, I use the function on this page: http://ryanbosinger.com/blog/2008/flashactionscript-innaccurate-math-results/ and it works – Alan Mar 12 '14 at 04:03
0

used the function on this page: http://ryanbosinger.com/blog/2008/flashactionscript-innaccurate-math-results/ the issue got resolved

Alan
  • 178
  • 1
  • 10