Money and rounding
Thor represents monetary amounts with a currency code and an integer centAmount. The integer is expressed in the currency’s minor unit; despite the field name, the number of fraction digits is determined by the currency.
Store and calculate integers
For EUR, a centAmount of 1099 represents EUR 10.99. A zero-decimal currency uses whole units, while currencies with three fraction digits use thousandths. Use ISO 4217 currency metadata when formatting and parsing; never divide every amount by 100 unconditionally.
Keep arithmetic in minor-unit integers or a decimal money type. JavaScript binary floating-point arithmetic such as 10.99 * 3 is not an authoritative total.
Rounding modes
Each store has a default price rounding mode and a default tax rounding mode:
| Mode | Midpoint behavior |
|---|---|
TO_EVEN | Round to the nearest even result |
AWAY_FROM_ZERO | Round away from zero |
TO_ZERO | Round toward zero |
Thor applies these configured modes while calculating commerce totals. Price and tax can round at different stages, so summing independently formatted display strings can differ from the returned total.
Worked display example
If Thor returns { centAmount: 1099, currencyCode: "EUR" }, format it with EUR’s two fraction digits as €10.99. If three units are in a cart, render the line total returned by Thor rather than calculating it from the formatted string. The same rule applies to subtotal, discounts, tax portions, shipping, and grand total.