Computer Arithmetic
Why are monetary amounts often handled as integers in the smallest unit (one yen or one cent) rather than as binary floating point?
- AFloating point cannot represent large amounts of money at all
- BIntegers always use less memory than floating-point numbers
- CDecimal fractions are inexact in binary, causing errors
Show answer and explanation
Answer: C. Decimal fractions are inexact in binary, causing errors
Decimal 0.1 and 0.01 are not exact in binary floating point and are stored as rounded approximations. Repeated additions accumulate error, so totals can end up a yen or cent off. Since money tolerates no such error, calculations use integers counting the smallest unit, or decimal formats. Floating point can approximate large amounts, and memory usage is not the reason.
- A. Large values can be approximated; the issue is error.
- B. Memory usage is not the main reason.
- C. Correct. Decimal fractions are not exact, and the errors are unacceptable.