1 Reply Latest reply on Jul 19, 2007 3:25 PM by Newsgroup_User

    Error in Round

    Yorchxxx
      I try thist:
      trace(Math.round(1.265*100)/100); Flash Result: 1.26 Error, the correct answer it's 1.27
      Any Ideas?

      Jorge.
        • 1. Re: Error in Round
          Level 7
          Neat. This may actually be a Flash bug. Here's the calculation:

          var num:Number=1.265;
          num*=100;
          trace ('num='+num);
          trace(Math.round(num)/100);

          ...and here's the trace:

          num=126.49999999999999
          1.26

          So it explains why the number is being rounded the way it is but clearly
          the result is wrong. This might be something to bring to Adobe's attention!

          Regards,
          Patrick

          Yorchxxx wrote:
          > I try thist:
          > trace(Math.round(1.265*100)/100); Flash Result: 1.26 Error, the correct answer it's 1.27
          > Any Ideas?
          >
          > Jorge.

          --
          http://www.baynewmedia.com
          Faster, easier, better...ActionScript development taken to new heights.
          Download the BNMAPI today. You'll wonder how you ever did without it!
          Available for ActionScript 2.0/3.0.