4/7 Cash register totals at 30.600000000000005


#1

My code returns a tiny weirdly long decimal number...Why is the ....5 at the end there?
Programm asks me, if I added everything 4 times...

var cashRegister = {
total:0,
add: function(itemCost){
this.total += itemCost;
},
scan: function(item,quant) {
switch (item) {
case "eggs": this.add(0.98 * quant); break;
case "milk": this.add(1.23 * quant); break;
case "magazine": this.add(4.99 * quant); break;
case "chocolate": this.add(0.45 * quant); break;
}
}
};

// scan each item 4 times
cashRegister.scan("eggs",4);
cashRegister.scan("magazine",4);
cashRegister.scan("milk",4);
cashRegister.scan("chocolate",4);

//Show the total bill
console.log('Your bill is '+cashRegister.total);


#2

@seulberg1,

Please look at the explanation
= http://discuss.codecademy.com/t/4-7-i-have-to-scan-it-more-than-once/11394/5?u=leonhard_wettengmx_n


#3

It could be the order which you are multiplying them in. for example mine was in

cashRegister.scan('eggs', 4);
cashRegister.scan('milk', 4);
cashRegister.scan('magazine', 4);
cashRegister.scan('chocolate', 4);


#4

@leonhard_wettengmx_n

thanks for the feedback.

I helped myself with
cashRegister.total = Math.round(cashRegister.total*10)/10
but was surprising to me:)