One of the most common bug reports on a crypto checkout isn't about reorgs or webhooks. It's a customer who paid exactly what the screen told them and got an order stuck in "partially paid", short by a fraction of a cent.
Nobody had stolen anything. The amount had just been through too many conversions: a USD price, a float in JavaScript, a token with six decimals, a wallet that rounded the display, and an exchange that shaved a little off for its own fee. Each step was "basically right". Together they produced an order a human had to look at.
This post is about that boring layer: turning a price in dollars into an amount on chain, and deciding when the money that arrives is "the same" as the money you asked for.
Store money as integers, in the unit the chain uses
This is the rule everyone knows and still breaks. Don't hold token amounts in floats, not even briefly.
Every asset has a smallest unit and a number of decimals:
- Bitcoin: 8 decimals (satoshis)
- Ether and most EVM-native coins: 18 decimals (wei)
- USDC and USDT: usually 6 decimals, though check the contract on each chain rather than assuming
So an invoice for 49.99 USDC is 49990000 base units. Store that integer. Compare integers. Only format it for humans at the edge.
// amounts in base units, as bigint
function toBaseUnits(decimalString: string, decimals: number): bigint {
const [whole, frac = ""] = decimalString.split(".");
if (frac.length > decimals) throw new Error("too many decimal places");
return BigInt(whole + frac.padEnd(decimals, "0"));
}
toBaseUnits("49.99", 6); // 49990000n
If your price comes in as a number from somewhere else, convert it to a decimal string with an explicit precision before it touches this function. 0.1 + 0.2 is still 0.30000000000000004 and it will still end up on someone's invoice.
Decide who rounds, and in which direction
Converting USD to a volatile coin always produces more digits than you want. 49.99 USD at some BTC rate is a long tail of satoshi fractions. You have to round, and the direction is a business decision:
- Round up and the customer occasionally pays a hair more than the sticker price. Nobody complains about a satoshi.
- Round down and you occasionally receive a hair less, which, depending on how strict your matching is, can turn into a partial payment.
My preference is to round the requested amount up to the smallest unit, every time, and show the customer the exact rounded figure with a copy button. What they copy is what I compare against. That alone prevents a whole class of "I paid what it said" tickets.
Exact amounts beat "about this much"
The checkout should never show a rounded-for-humans number as the thing to send. "0.00073 BTC" on screen while the system expects 73412 sats is how you manufacture partial payments.
Show the full amount. Make it copyable. Put it in the QR code or wallet link so the customer's wallet fills it in. Coldtill's hosted checkout does exactly this: exact amounts, copy buttons and wallet links, plus live confirmation progress once the transfer is seen.

The amount on screen is the amount the system matches. No "approximately".
Stablecoins mostly make this go away (mostly)
If you settle in USDC or USDT, the conversion question nearly disappears: one dollar is roughly one token and 49.99 is 49.99. The exchange-rate step is gone, so the rounding step is gone with it.
Two things remain:
- Decimals still differ. A 6-decimal token and an 18-decimal token on another chain are not interchangeable integers. Normalise per asset, per chain.
- Exchanges and bridges take a slice. A customer withdrawing from an exchange may see the fee taken from the amount instead of on top of it. That's not a rounding issue, it's a genuinely short payment, and your system should treat it as one.
Pick a tolerance and write it down
Even with all of the above, you'll see payments that differ from the order by a trivially small amount. You need a rule for "close enough", and the rule needs to be explicit, small and tested.
The Coldtill WooCommerce plugin is a nice concrete example because its behaviour is documented on the listing: if the amount Coldtill reports doesn't match the order total, apart from a one-cent difference, the plugin adds an order note and leaves the status unchanged. The changelog even records the edge case being fixed, where a payment exactly one cent off had been left pending instead of marked paid. That's the kind of bug this whole post is about. The boundary condition is where it lives.
A tolerance like that has a few properties I'd copy:
- it's tiny, so it can't hide a real shortfall,
- it's expressed in the pricing currency (cents), not in token units that change meaning between assets,
- anything outside it doesn't silently fail or silently pass. It leaves a note and waits for a human.
const TOLERANCE_CENTS = 1n;
function classify(expectedCents: bigint, receivedCents: bigint) {
const diff = receivedCents - expectedCents;
if (diff >= -TOLERANCE_CENTS && diff <= TOLERANCE_CENTS) return "paid";
if (diff < 0n) return "partial";
return "overpaid";
}
Write tests for -1, 0, +1 and -2. The one that bites is always on the line.
Keep one source of truth for "paid"
The last trap is having two systems that each think they know the answer. If your shop computes "paid" from the webhook body and your gateway computes it from the chain, sooner or later they'll disagree by a cent.
Let the gateway decide, and have the shop act on that decision. Coldtill prices payments in US dollars and its watcher tracks fill state (paid, partially paid, cancelled) on your own server, then sends a signed webhook. The shop's job is to verify the signature and map the state, not to redo the maths. If you're curious how that's wired, the code for the self-hosted gateway is on GitHub at github.com/Coldtill/self-hosted-crypto-payment-gateway.

Payments with their state. Partial payments stay visible instead of vanishing into "failed".
The short version
- Integers in base units, never floats.
- Round the requested amount up, and show exactly what you'll match.
- Normalise decimals per asset and per chain.
- Have a small, written, tested tolerance in the pricing currency.
- One system decides "paid". Everything else listens.
None of this is clever. It's just the part of a crypto checkout that decides whether a real person gets an email saying their order is on its way, so it's worth getting boring and right.
Top comments (1)
the one-cent problem is usually born at the display layer: the wallet shows four decimals, the chain holds six, and the screenshot becomes the customer's evidence of what they sent. integer base units is table stakes, but the harder call is who rounds and in which direction, because round-up-per-order is a pricing statement, not a technical detail. one pattern that keeps humans out of the loop: absorb the drift into a daily tolerance bucket expressed in the pricing currency like your classify() does, so the only orders anyone sees are the ones that breach the bucket.