JavaScript · Middle · Question 73 of 75
How should money be stored to avoid 0.1 + 0.2 problems?
- ✓Correct answer: As integers in the smallest unit (cents) or with a decimal library, formatting only for display
- 2As floats rounded with
toFixed(2)after each operation - 3As strings and converted with
parseFloatwhen needed
Explanation
Binary floating point can't represent most decimal fractions exactly. Integer cents (or BigInt) keep sums exact; Intl.NumberFormat formats them for users.