
1. Re: Adding 2 Numbers loosing precission. Odd results.
BoNzO Oct 1, 2010 5:39 AM (in response to Aron manager)1 person found this helpfulThis is because of the floatingpoint numbers. Nothing you can do in your use case.
People usually develop their own "Money" or "Decimal" classes when they need high precision.

2. Re: Adding 2 Numbers loosing precission. Odd results.
JoshBeall Oct 1, 2010 5:40 AM (in response to Aron manager)1 person found this helpfulThat is frustrating. This is probably because decimal numbers are stored in the format specified by the IEEE Standard for Binary FloatingPoint Arithmetic (IEEE754). That format doesn't have perfect precision with floating point numbers and (as you've observed) sometimes the math operations don't output perfect results. You can read about that here (scroll to the section about the Number type, and then also read the comments)
http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_11.html
I can only think of a few suggestions:
1) Find an existing Decimal class library that can handle decimal number arithmetic with no loss of precision.
2) Write your own Decimal class library.
3) Beg Adobe to ship a Decimal class library with Flex :)
Josh

3. Re: Adding 2 Numbers loosing precission. Odd results.
JoshBeall Oct 1, 2010 5:42 AM (in response to JoshBeall)Oh, and of course in your case rounding probably is a workaround, at least with the example you posted. Since you're adding two numbers with a precision that goes out to 1/10th, you can round to the nearest 1/10th and it will give you the correct result. You know that the result can't have a component smaller than 1/10th, because that is the smallest component in your original arithmetic.

4. Re: Adding 2 Numbers loosing precission. Odd results.
JoshBeall Oct 1, 2010 6:10 AM (in response to JoshBeall)This might work for you:
http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&extid=1285018