A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: need help with sumple add subtract problem

  1. #1
    Member
    Join Date
    Mar 2003
    Posts
    50

    need help with sumple add subtract problem

    why is this happening?

    if you use a calculator or google 310 + (-303.3) you will get 6.7
    but when i do this is AS3 trace(310 + (-303.3)); i get 6.699999999999989

    i tried Math.ceil() and round() but cant get 6.7

    TY
    Last edited by mikemx; 12-01-2008 at 03:49 AM.

  2. #2
    Flashkit Veteran joejoe2288's Avatar
    Join Date
    Apr 2004
    Location
    Hickville, Oregon
    Posts
    2,554
    Probably has to do with the integer conversion type in Flash, try 310.0-(-303.3)
    I have had the same problem in Java, of course the compiler won't even let me subtract a double from an integer in that language.
    But my guess is that the compiler resets the 310 value to 310.00000000000000... in hopes of retaining double level precision. Try it out, tell me what happens I haven't used 3.0 so just offering my humble advice
    So tired of all the fighting....

    http://joejoe2288.kawanda.net

  3. #3
    Member
    Join Date
    Mar 2003
    Posts
    50
    nope,
    if i try 310.0-(-303.3) like you suggest i get 613.3

    so i tried
    trace(310.0 + (-303.3)) get 6.699999999999989

  4. #4
    Flashkit Veteran joejoe2288's Avatar
    Join Date
    Apr 2004
    Location
    Hickville, Oregon
    Posts
    2,554
    That is quite odd and I am very sorry, but I know little about the changes made in AS3 so my knowledge is limited, as if it wasn't already :P
    So tired of all the fighting....

    http://joejoe2288.kawanda.net

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center