javascript sum gives 6.569999999999999 instead of 6.57

Viewed 18

I was trying to solve a challenge, but I encountered this issue along the way the sum is supposed to be 6.57, but it gives 6.569999999999999

I have seen similar posts about this talking about it, but in technical terms and no solution, please provide any solution if you have one. thanks

let totalChange = 0;
let change = [
      [ 'FIVE', 5 ],
      [ 'ONE', 1 ],
      [ 'QUARTER', 0.5 ],
      [ 'NICKEL', 0.05 ],
      [ 'PENNY', 0.02 
    
    ] 
    ]
    
    change.forEach(element => totalChange += element[1])
    
    console.log(totalChange) // 6.569999999999999

0 Answers
Related