Valdhor already gave you all the info you need, but I like the sound of my
own fingers typing. I also like to procrastinate, so I'm in heaven right now
:p

   - Some numbers that are easy to represent in decimal are hard to
   represent in binary, just as some numbers that are easy to represent in base
   60 are hard to represent in decimal (such as 1/3).
   - Your calculations are safe enough: Number has a very high precision and
   calculations are carried out with full precision. It's just when testing for
   equality that you can run into problems -- I'm guessing this is where you
   noticed the discrepancy?
   - When comparing for floating-point numbers for equality, you need to
   specify a tolerance too. Most unit-testing frameworks provide this for their
   floating-point asserts. And when I was doing financial apps, we did the same
   thing. If you *really* need higher precision, you'll need a BigNumber
   implementation for AS3, of which there are several. The AS3Crypto library
   has one I believe...

Chyaaaars :)
Jules

On Thu, Dec 18, 2008 at 03:15, Ken Johnson <[email protected]> wrote:

>   Hi Everyone -
>
> Given the following code:
> var num1:Number = 0.72;
> var num2:Number = 0.198;
> var num3:Number;
>
> num3 = num1;
> num3 += num2;
>
> I would expect num3 to equal 0.918.
>
> Instead, it equals 0.9179999999999999.
>
> And when I apply a number formatter with a precision of 2, I get 0.91.
>
> I am performing financial calculations, and this is not acceptable.
>
> Am I doing something wrong here?
>
> Thanks for your help!
> Ken
>
>  
>



-- 
Cheers,
Jules
--
Jules Suggate
Owner and Technical Lead
Uphill Sprint Limited

+64-21-157-8562

Reply via email to