0

The last line reads "The grand total is 41.300000000000004". I've been running it in repl.it.

var groceryList = [
    {food: "Mangos", price: 3.56},
    {food: "Grapes", price: 4.23},
    {food: "Chicken", price: 10.98},
    {food: "Sweet Potatoes", price: 7.94},
    {food: "Asst. Nuts", price: 6.54},
    {food: "Yogurt", price: 5.32},
    {food: "Papya", price: 2.73}
    ];

function shopping(items){
    console.log (items.food + " = " + items.price + ".");
    }
var grocery;
var total=0;
for ( grocery in  groceryList){
     
    total=total+groceryList[grocery].price;
    shopping(groceryList[grocery]);
}

    console.log("The grand total is " + total);
BigPapa
  • 17
  • 1
  • 1
    Take a look at this web-site - http://floating-point-gui.de/ – nril Aug 03 '15 at 22:35
  • 1
    [How to deal with floating point number precision in JavaScript?](http://stackoverflow.com/a/3439981/2549512) – Brenne Aug 03 '15 at 22:39
  • Use the value in cents as an integer; for instance, {food: "Mangos", price: 356}. Then divide by 100 for display; or better yet, just shift the decimal point. – Dan Korn Aug 03 '15 at 23:13
  • – Jordan Davis Aug 03 '15 at 23:14
  • @BigPapa copy and paste the above code in if your still looking for the answer, you should use the Math.round() method. – Jordan Davis Aug 03 '15 at 23:14

0 Answers0