Never represent money as a floating-point number. The API sends and receives integers in the smallest unit of the currency. Your code must do the same.
For Brazilian Real (BRL):
Display value
API value (amount integer)
R$ 1.00
100
R$ 150.00
15000
R$ 1,234.56
123456
R$ 10,000.00
1000000
The conversion is fixed: apiValue = displayValue × 10^decimals.
const cents = BigInt(response.amount); // safe for all valuesconst reais = Number(cents) / 100; // safe ONLY for display; precision lost on large values
Python:
cents = response['amount'] # already an intreais = cents / 100 # fine; Python ints are arbitrary precision
Go / Java / Rust: native int64 is more than sufficient — BRL values up to ≈ 92 quadrillion fit.
// ✗ Wrong — precision loss on certain valuesconst cents = Math.round(reais * 100);// ✓ Right — parse as integers from the startconst cents = parseInt(reais.replace('.', ''), 10);
If you must accept user-typed decimal input, validate it as a string against ^\d+(\.\d{1,2})?$ (for BRL) and convert by digit manipulation, not multiplication.