Floating-point types like Double cannot represent decimal fractions exactly, making them unsuitable for monetary calculations. Three approaches exist: binary floats (fast but imprecise), integer minor units (exact but can't divide cleanly), and BigDecimal (correct but JVM-only). Kotlin Multiplatform removes BigDecimal from commonMain, forcing teams to build expect/actual wrappers backed by BigDecimal (JVM), NSDecimalNumber (iOS), and decimal.js (JS/Wasm) — three engines with different precision limits and failure modes. The post walks through BigDecimal's own traps (constructor lies, scale-sensitive equality, division exceptions, rounding modes) and introduces Deci, an open-source KMP library that normalizes behavior across all three backends, enforces explicit rounding, and serializes money as strings.
Table of contents
Why your money has been quietly leakingThree honest ways to hold moneyBigDecimal is right. It still has three traps.Get Konstantin Merenkov’s stories in your inboxThe twist nobody warns about in KMPChoose on purpose: four questions21.7K Impressions1 Comment