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
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!...
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.