Hey All,
I am having issues subtracting numbers – yes subtracting haha
Basically I add 0.99 + 0.99 + 0.99
I get: 2.97 - great!
Now when I subtract 0.99 one at a time (using AS) It goes like this:
2.97 - 0.99 = 1.98
1.98 - 0.99 = 0.99
0.99 - 0.99 = -2.22044604925031e-16
?? how did we get that number
My code
total_price is defined as a number and starts at 0.00.
Eg: var total_price:Number = 0.00;
songs is an array that contains information about each song that is loaded - in the multi-level array number 5 represents the price of the song. Which on eash song is defaulted to 0.99.
function addItem(element){
var track = substring(element, 27, 1);
_root.total_price+=Number(songs[track][5]);
_root.price.cost.text="$"+_root.total_price;
}
function removeItem(element){
var track = substring(element, 27, 1);
_root.total_price-=Number(songs[track][5]);
_root.price.cost.text="$"+_root.total_price;
}
Anyone have any clue why I get such a random number such as “-2.22044604925031e-16”?
If I remove and add only 2 sets of 0.99 is comes out 0 - its only when I do more then 2 calculations.
Thanks for any advice!