This content has been marked as final.
Show 7 replies

1. Re: Simple Math Calculation is incorrect
SymTsb Aug 30, 2007 11:43 AM (in response to injpix)(Assuming AS3)
use the toFixed method of the Number class. Keep in mind that this returns a string value so you'll have to type cast it back to a number.
var myNumber:Number = new Number(999.43);
var result:Number = myNumber  999;
var precise:String = result.toFixed(2);
result = Number(precise); 
2. Re: Simple Math Calculation is incorrect
injpix Aug 30, 2007 2:03 PM (in response to injpix)Ah thanks, that is nice to see for AS3, but I am using AS2 here still. Just out of curiosity, would you know why it is doing this? 
3. Re: Simple Math Calculation is incorrect
SymTsb Aug 30, 2007 2:16 PM (in response to injpix)it's an issue of precision. I believe you can still do something similar in AS2. I believe the Number class in AS2 allows you to convert a number to a string which you could then concatenate with the Sring class methods and convert back to a number. 
4. Re: Simple Math Calculation is incorrect
kglad Aug 30, 2007 3:50 PM (in response to injpix)the reason for the apparent error is because flash is performing arithmetic on a binary computer. within the limits of flash'es accuracy (16 digits),
0.42999999999995 = .43
to eliminate those errors, you can use integer arithmetic or the flash string methods. integer arithmetic is probably preferable if you're doing arithmetic operations. 
5. Re: Simple Math Calculation is incorrect
injpix Aug 30, 2007 4:18 PM (in response to injpix)ah...I understand now, thanks to the both of you. 
6. Re: Simple Math Calculation is incorrect
kglad Aug 30, 2007 4:24 PM (in response to injpix)you're welcome. 
7. Re: Simple Math Calculation is incorrect
SymTsb Aug 30, 2007 5:38 PM (in response to injpix)you're welcome.1 person found this helpful