Numeric precision is the amount of numerical detail a representation or calculation can retain. In Clojure, precision becomes practical when floating-point rounding, BigDecimal arithmetic, money, or large-scale computation can make small errors accumulate. section 5.11 section 5.13
Precision affects arithmetic in several connected ways:
- double uses binary floating-point representation, so ordinary decimal fractions can produce visible artifacts such as 0.6100000000000001. section 5.11
- BigDecimal preserves decimal-oriented calculation but can throw ArithmeticException for non-terminating results unless a precision and rounding mode are supplied. section 5.11
- Clojure’s numeric contagion rules roughly promote results toward the most precise operand, but explicit design is safer when precision matters. section 5.13
Controlling decimal division
(/ 22M 7) raises an ArithmeticException because the decimal expansion does not terminate. Wrapping the operation controls the result: (with-precision 4 (/ 22M 7)) returns 3.143M. A rounding mode can make the policy explicit, as in (with-precision 5 :rounding DOWN ...). section 5.11
Listing 5.7. → Arbitrary Precision Math, BigDecimal Precision, Precision Settings
(with-precision [precision & exprs])
Browse the compact contract for with-precision, including precision bounds, supported rounding modes, and wrapped expressions. section 5.11








