Development and QA

SMS API amounts: four-decimal USD displays and exact units

Use integer *_units for accounting, keep USD display formatting separate and test rounding with fictional examples before reconciling balances.

Three containers show available funds, a reservation and a settled charge, with a separate return arrow.

A four-decimal price is easy to read, but rounding can alter the sum of several values. Store the exact amount separately from the string used in the interface.

Read the money contract

Lucky Monkey uses USD. Display amounts are strings with four decimal places. Integer *_units fields preserve exact amounts, with 1 USD equal to 1,000,000 units.

Do not import another supplier's scaling assumptions. A Lucky Monkey integration must use its documented fields and unit scale.

Work through a fictional example

Suppose a fictional amount is 0.123456 USD, or 123456 units. Two such amounts total 246912 units, equivalent to 0.246912 USD. Rounding each first to 0.1235 produces a different sum of display values.

These are arithmetic examples, not current prices. They show why display rounding comes after exact calculation.

Keep representations consistent

  • Use the documented integer units for accounting.
  • Format the final display separately.
  • Do not mix units and USD in one variable.
  • Check range and sign requirements against the schema.

Use integers or exact decimal arithmetic with an explicit scale. Ordinary binary floating-point values should not be the accounting source of truth.

Verify with test data

Compare sums of rounded strings with sums of units, including small fictional amounts. Check reserved and available balances separately: they represent different states, not two labels for one charge. Consult the API contract and balance-state explanation.

Sources and further reading

← All articles