Hello, everyone! I need some help.
I am in Build a Cash Register of JavaScript Algorithms and Data Structures (Beta).
I want to calculate how many units of every denomination with cid.forEach(arr=>arr[1] / responsive denomination);
let cid = [
["PENNY", 1.01],
["NICKEL", 2.05],
["DIME", 3.1],
["QUARTER", 4.25],
["ONE", 90],
["FIVE", 55],
["TEN", 20],
["TWENTY", 60],
["ONE HUNDRED", 100]
];
responsive denomination part:
denomination = {
penny: 0.01,
nickel: 0.05,
dime: 0.1,
quarter: 0.25,
dollar: 1,
five: 5,
ten: 10,
twenty: 20,
"one hundred": 100
}
but I got this:
{ penny: 101,
nickel: 40.99999999999999,
dime: 31,
quarter: 17,
one: NaN,
five: 11,
ten: 2,
twenty: 3,
'one hundred': 1 }
Why do I here get the nickel of
40.99999999999999
I thought the nickel should be 41, because it is the result of 2.05 / 0.5. Except nickel, all the rest are right numbers. Why ?
So can someone helps me ? Do I miss something ? What happened here ?