NewWork mode: your Claude Code or Codex on work calls, answering from your project's codeSkip to content
Middle+1 view

What is the result of subtracting 1 - 0.7 - 0.3, and why?

Practice

Asked at

AI answer

The result is usually close to 5.551115123125783e-17, not exactly zero. Binary floating-point cannot represent the decimal fractions 0.7 and 0.3 exactly, so subtraction introduces a rounding error. For monetary values, it’s better to store an integer number of the smallest units (for example, cents) or use a decimal arithmetic library.