Currency Code Tools

Currency code tooling: ISO 4217 three-letter codes, symbols and per-currency minor units, why money arithmetic uses integers rather than floats, rounding and floating-point pitfalls in conversion, and the symbol-versus-code localisation trade-off.

Currency codes look like a few letters but carry precision, rounding and localisation details that matter.

Approach Comparison

AspectFloating pointInteger in minor units
PrecisionBinary cannot represent decimals exactlyExact
AccumulationErrors accumulateNone
Representing 1.231.23, unstable123
RoundingImplicit and uncontrolledExplicit and controlled
Database columnDECIMAL or FLOATBIGINT or INT
JSON transportMay show precision artefactsNo such issue
At display timePrint directlyConvert per currency minor units
Applies toScientific computing, graphicsAccounting, amounts, billing

Edge Cases

  • ISO 4217 defines minor units per currency: CNY, JPY and KRW use 0, USD and EUR use 2, and several Middle Eastern currencies use 3.
  • Converting between currencies is not one multiplication by a rate plus one by 100; minor-unit differences must be handled separately.
  • Floats in JSON can show precision artefacts in some languages, so amounts are better transported as strings or integers.
  • The rounding direction (up, down, half-up) must be specified explicitly, since defaults differ across languages.

Common Pitfalls

  • Multiplying and dividing by 100 for every currency, inflating JPY amounts a hundredfold.
  • Accumulating amounts in floating point and ending a batch off by a few cents.
  • Storing money in a FLOAT column, where accumulated error surfaces during reconciliation.
  • Transporting amounts as JSON floats, where client and server round differently and totals diverge.

Related Tools