Have you performed simple arithmetic operations like 0.1 + 0.2? You might have gotten something strange: 0.1 + 0.2 = 0.30000000000000004.
Have you performed simple arithmetic operations like 0.1 + 0.2? You might have gotten something strange: 0.1 + 0.2 = 0.30000000000000004.
How would you implement this in code?
I don’t have much JavaScript experience, but maybe
.toFixed()
will help here. Playground (copy the below code to the playground to test): https://playcode.io/javascriptoutputs: