Amounts and precision
Monetary amounts are easily corrupted in transit. Floating point numbers cannot represent most decimal values exactly, and an amount that is rounded or misread by even the smallest fraction can break reconciliation. Mitu follows a consistent set of rules for representing amounts, so every value arrives in your systems exactly as it was intended.
Representing amounts
Send amounts as numbers in requests
When you create a payment link, invoice or plan, send the amount as a number in the currency’s main unit, such as 25.00 for twenty five US dollars, never in cents or other minor units.
Read amounts as decimal strings in responses
Amounts in responses and events are returned as strings, so that no precision is lost on the way to your systems. Parse them with a decimal type, never with a floating point number.
Precision by currency
Precision practices
- Use a decimal type throughout
Store and calculate amounts with a decimal type in your database and code, so values are never altered by conversion. - Never round received amounts
Record the amount exactly as returned, and round only for display. - Reconcile on value, not on formatting
Match payments to records by decimal value and currency, never by comparing formatted text.
Following these rules ensures that the amount a customer was asked to pay, the amount they paid and the amount in your records always agree, to the smallest unit.