Crypto payment amounts: strings, decimals and rounding
Ether has 18 decimals, Bitcoin 8, USDT on TRON 6 and BONK 5. A JavaScript number holds about 15 to 17 significant digits. That gap is why every amount in the easyway API, in requests and in responses, is a decimal string such as "49.90". This post covers what the API accepts, which way each amount is rounded, and a small Node.js helper for adding amounts up without losing digits.
What the API accepts
amount on POST /v1/invoices and POST /v1/payouts must be a JSON string of plain digits. It can have up to 20 digits before the point and up to 18 after it. No sign, no exponent, no thousands separator. Anything else is refused before it reaches an invoice:
{ "amount": 49.9, "currency": "USD" } → 400 validation_error, fields ["amount"]
{ "amount": "49.90", "currency": "USD" } → 201, "amount": "49.9"
{ "amount": "1e3", "currency": "USD" } → 400 validation_error
{ "amount": "1,000.00", "currency": "USD" } → 400 validation_errorFor a USD price, send cents: "49.90". More decimals are accepted and used in the conversion, but the price is shown with two decimals and cut, not rounded, so "49.999" is displayed as 49.99 while the coin amount is worked out from 49.999. Keep your prices in integer cents and format them as a string when you call the API.
Which way each amount is rounded
Inside the gateway, every amount is a whole number of 10-18 units held in a BigInt. Floating point is never used for money. Rounding happens in two places only, and always in a fixed direction:
| Amount | Rounded | To |
|---|---|---|
pay_amount of a USD invoice | Up | 6 decimals for stablecoins, 8 for other coins (fewer if the coin has fewer) |
pay_amount of an invoice priced in a coin | Up | The coin's own decimals |
The 0.5% fee (fee_amount) | Down | The coin's own decimals |
received_amount, remaining_amount, net_amount | Cut | The coin's own decimals |
Rounding the quote up means a customer is never asked for a fraction of a coin's smallest unit. Rounding the fee down means it never takes more than 0.5%. In the gateway's own tests, a 25 USD invoice paid with 25.01 USDT gives fee_amount 0.12505 and net_amount 24.88495. Rate sources, the 15-minute price limit and the choice between USD and coin prices are covered in pricing an invoice in USD or in the coin.
Decimals, quotes and the smallest payment, per coin
A coin's decimals are in GET /v1/assets. A quote for a USD invoice can have fewer decimals than the coin itself. Each network also ignores deposits below a small floor, because those are usually spam:
| Asset id | Coin decimals | Quote decimals (USD invoice) | Smallest deposit counted |
|---|---|---|---|
USDT_TRC20 | 6 | 6 | any amount |
USDT_BEP20 | 18 | 6 | 0.01 |
BTC | 8 | 8 | 0.00001 |
ETH | 18 | 8 | 0.00001 |
TRX | 6 | 6 | 0.1 |
XRP | 6 | 6 | 0.01 |
SHIB_ERC20 | 18 | 8 | 2000 |
BONK_SOL | 5 | 5 | 3000 |
Most coin pages give the floor for their coin. Withdrawal fees and minimums are on the pricing page.
Reading amounts back
Responses drop trailing zeros. A price sent as "25.00" comes back as "25", and a quote of 49.000000 USDT as "49". So never compare amounts as strings, and never run them through parseFloat before adding them up. Turn each one into integer units with the coin's decimals, do the maths in integers, and format the result only at the end. For reporting you rarely need to compare anything yourself: the status field already says paid or underpaid, after your underpayment tolerance (0 to 5%, 1% by default) has been applied.
// amounts.mjs: Node 18+, no npm install. Turns the API's decimal strings into
// integer units (BigInt), so nothing is ever rounded by floating point.
export function toUnits(s, decimals) {
if (!/^\d{1,20}(\.\d{1,18})?$/.test(s)) throw new Error(`not a plain decimal: ${s}`);
const [whole, frac = ""] = s.split(".");
if (frac.length > decimals) throw new Error(`${s} has more than ${decimals} decimals`);
return BigInt(whole) * 10n ** BigInt(decimals) + BigInt(frac.padEnd(decimals, "0"));
}
export function fromUnits(units, decimals) {
const scale = 10n ** BigInt(decimals);
const frac = (units % scale).toString().padStart(decimals, "0").replace(/0+$/, "");
return frac ? `${units / scale}.${frac}` : `${units / scale}`;
}
// Net received per coin for a list of invoices from GET /v1/invoices,
// using the `decimals` of each asset from GET /v1/assets.
export function netPerAsset(invoices, assets) {
const decimals = new Map(assets.map((a) => [a.id, a.decimals]));
const totals = new Map();
for (const inv of invoices) {
if (!inv.pay_asset || inv.net_amount === "0") continue;
const d = decimals.get(inv.pay_asset);
totals.set(inv.pay_asset, (totals.get(inv.pay_asset) ?? 0n) + toUnits(inv.net_amount, d));
}
return [...totals].map(([id, units]) => ({ asset: id, net: fromUnits(units, decimals.get(id)) }));
}Run on Node 22 with four paid invoices:
netPerAsset([
{ pay_asset: "USDT_TRC20", net_amount: "48.755" },
{ pay_asset: "USDT_TRC20", net_amount: "0.995" },
{ pay_asset: "ETH", net_amount: "0.014925373134328358" },
{ pay_asset: "ETH", net_amount: "0.1" },
], [{ id: "USDT_TRC20", decimals: 6 }, { id: "ETH", decimals: 18 }])
// → [ { asset: "USDT_TRC20", net: "49.75" }, { asset: "ETH", net: "0.114925373134328358" } ]
Number("0.014925373134328358") + 0.1
// → 0.11492537313432837 (the last digits are already gone)If you store amounts in a database, use a decimal column wide enough for 18 decimals, such as MySQL DECIMAL(38,18), which is what the gateway uses. Never use FLOAT or DOUBLE. The same rule holds in Python (Decimal), PHP (strings or bcmath) and Go (math/big). Every endpoint is listed on the crypto payment API page.