Here's a direct lift from something I posted on the OSFlash list...

This is all to do with floating-point precision and that you can't
represent all numbers exactly (0.1 is one culprit) in the IEE
standard. There are plenty of sites about this - see here, for
example:
http://en.wikipedia.org/wiki/Floating_point#Problems_with_floating-point

You are almost certainly better off working with integers; or perhaps
multiplying up your numbers by 100 before working with them, then
reducing as a final step, or something similar.

This is not just limited to Flash/AS2 as an issue.

Ian

On 4/28/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

Apologies if this is common knowledge, but I've just come across a huge maths 
problem in Flash... as I've mentioned before I'm working on an online trading 
system where real people make or lose real money, sometimes a huge amount of 
it, so this isn't funny...

Here's some simple arithmetic..

var a:Number = 171.9;
var b:Number = 172.2;
var c:Number;
c = b - a;

Now an elementary school kid would probably give the answer 0.3
Unfortunately Flash has other ideas...

trace(c);
0.299999999999983

I'm a bit shocked to be honest. Am I imagining it?

I'm aware that AS3 introduces proper integers and floats for arithmetic, but 
that doesnt address my problem now.

What says the wise Chattyfig community??
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to