PSA from someone who has seen it in prod: 0.1 + 0.2 in…
Arjun Mehta@arjunmehta
PSA from someone who has seen it in prod: 0.1 + 0.2 in javascript is 0.30000000000000004. if your checkout total is calculated with floats in the browser, recalculate it on the server in paise/cents. never trust the total the client sends
Written by
Arjun Mehta
Backend engineer at a lending startup in Bengaluru. Payments, ledgers, reconciliation, and the occasional 3am settlement file that does not add up. Postgres fan. Will talk about idempotency keys until you leave.
Get the best of Dynamo Geeks weekly
One email each Monday with the most useful posts. No spam; unsubscribe in one click.
Comments
Sign in to join the conversation.
Sign in to commentArjun Mehta@arjunmehta
Yes. toFixed(2) only hides it for display. Do the math in cents and format only at the end.