1 Reply Latest reply on Nov 14, 2007 3:09 AM by Darkout_Full_Jazz

    bug in Number.toFixed() method?

    IonicRobin Level 1
      (This is a cross-post from the ActionScript 3.0 forum, since I didn't get any replies)

      I seem to have come across a problem with the Number.toFixed() method in Flex Builder 2

      The following code:
      var test:Number = 5e-5;
      trace(test);
      trace(test.toFixed(0));

      Outputs:
      0.00005
      1.

      Is this a known bug? Is there a work-around or fix at present?

      Regards,

      Robin
        • 1. Re: bug in Number.toFixed() method?
          Darkout_Full_Jazz
          Example 1
          var x:Number = 10.03;
          var y:Number = 0.07;
          var z:Number = 9.9;

          var total:Number = 0;
          total += x; //10.03
          total += y; //11.0000001
          total += z; //20.0000005 [ Why 0.0000005 ?]


          Example 2
          var x:Number = 20;
          var y:Number = 10.07;
          var z:Number = 9.93;

          var total:Number = 0;
          total = x; //total = 20
          total -= y; //total = 9.93000001 0.00000001?
          total -= z; //total = -4.1000005 The result must be 0 zero.

          How can I fix this?