Unknown JavaScript behaviour

Hello Campers, while working on the last JS project Cash Register, I got some behaviour from JS I couldn’t understand; can someone help me understand what’s wrong is going on

console.log('before cashReturn: '+cashReturn)
cashReturn -= deduced
console.log('deduced: '+deduced)
console.log('after cashReturn: '+cashReturn)

The output is like this

before cashReturn: 96.74
deduced: 80
after cashReturn: 16.739999999999995

cashReturn after subtraction should be 16.74 and not 16.739999…

how do you justify this behaviour ?

p.s: deduced has this value for now :

deduced = Math.floor(cashReturn/amounts[value[0]]) * amounts[value[0]]

Thanks in advance

take a look at this

1 Like

ohhhh I got it now Thank you

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.