+ 1

Error when entering numbers

If you try my code and add a cost of 1, 2 or 0.10 or 0.20 dollars they will appear with a few dollars less at the beginning for some apparent reason https://sololearn.com/compiler-playground/WG6dmdzWRI0j/?ref=app

21st Apr 2024, 1:23 AM
<YostDev>
<YostDev> - avatar
1 Resposta
+ 5
Floating-point numbers in JavaScript are represented as binary fractions, and some decimal numbers cannot be represented precisely in binary. This can lead to small inaccuracies in calculations, especially when dealing with arithmetic operations involving floating-point numbers. This is the reason the numbers appearing with a few dollars less than expected at the beginning. To fixed this issue, you can use JavaScript's toFixed() method to format the numbers to a specific number of decimal places.
21st Apr 2024, 1:56 AM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar