0
let numbers = [
      ["PENNY", 1.01], 
      ["NICKEL", 2.05], 
      ["DIME", 3.1], 
      ["QUARTER", 4.25], 
      ["ONE", 90], 
      ["FIVE", 55], 
      ["TEN", 20], 
      ["TWENTY", 60], 
      ["ONE HUNDRED", 100]
    ];

let totalOfNums = numbers.reduce((acc, val) => acc + val[1], 0);

console.log(totalOfNums);

The correct summation should be 335.41 however for some reason my output is 335.40999999999997.

I've tried let totalOfNums = numbers.reduce((acc, val) => (acc + val[1] * 100), 0); and got 33541 but when I tried to divide by 100, it gives wrong answer let totalOfNums = numbers.reduce((acc, val) => ((acc + val[1] * 100)/ 100), 0);

What am I doing wrong? I will also appreciate if you could also give some other ways to get the correct summation

janjarobo
  • 9
  • 3

1 Answers1

0

+totalOfNums.toFixed(2)

Hope this helps

Boyz
  • 9
  • 2