2 Replies Latest reply on Jul 15, 2006 7:09 AM by al_zaharia

    Number Multiplying Issue...

      Hello everybody.

      I have a problem when I try to multiply a variable - a Number variable with two decimals, to be more exact - with another Number variable with just one decimal. The thing is sometimes ActionScript multiplies the two variables ok (i.e. the result has three decimals), but sometimes, if I expect the result to be, let's say, 34.125, the result given by ActionScript is either 34.1249...9 either 34.1250...01.

      I managed to solve this by having the result copied in an Array and chopping off some digits or rounding the fractional part of the result.... a sort of ugly trick I wouldn't want anyone to be obliged to use.

      I'd like to know if this is a normal behaviour or if anyone experienced this kind of problems before. Please help!...

      By the way, I use Flash 8.


        • 1. Re: Number Multiplying Issue...
          blemmo Level 1

          this is quite normal when calculating with decimals, not only in Flash. The best way to avoid this is by calculating with full numbers instead of decimals. To do this, multiply your numbers with 100 first. This gets you full numbers that you can use for your calculations. After that, reverse this by dividing the result by 10000 (this is for a multiply operation, because both operands were multiplied by 100 >> 100*100=10000), and you should get a result that's exact.

          • 2. Re: Number Multiplying Issue...
            al_zaharia Level 1
            Thanks, Blemmo! Come to think of it, your solution is a lot better than mine.
            ...Though I was hoping I might get past this problem, you know, like in a normal PL with normal data types...

            Thanks again and good luck with your work,