This content has been marked as final. Show 7 replies
flash uses binary, not decimal, arithmetic.
in general with flash, your calculations will be accurate to 16 digits.
The strange part is that under AS2, this same script produces the correct decimal representation in the trace window. I know that behind the scenes it is facing the same problem, but it seems they added something to it to it (like any 1.50 hand held calculator) to make it show what we need.
In another thread I had heard that because AS3 is trying to be more ECMA (I think that is it) compliant it is taking the warts and all.
But who know this was a bigger problem early on with AS2 as well and it did go away – or at least a bit. Maybe they will "fix" it here to. But I wouldn't count on it!
Considering how it all seems to be intended for serious applications rather than artistic fun, you'd think the number thing would work appropriately for commerce.
Here's a workaround-- you've probably thought of it--
var num:Number = new Number(32.55*100);
var num2:Number = new Number(10*100);
var num3:Number =num - num2;
trace(Math.round(num3)/100);//what you want
Thank you for your answers.
i've thought about working with integers values and divide it to make the good result. But multiply and divide a Number may also cause bad result ...
that's accurate to 16 digits. if you need greater accuracy you cannot use flash.
Yes, but if you're using this for a commerce site, that's a pretty strange looking total you're going to ask them for!
if you're using currency, format your answer accordingly. flash has no problem doing that.
in fact, yesterday i posted code for a function that formats numbers to 2 decimal places because someone wanted a currency format in this forum.