Menu

Money Math for a Freelance Fee Calculator in JavaScript: Integer Cents, Rounding on Purpose and Currency Symbols That Don't Pretend to Convert
📰

Money Math for a Freelance Fee Calculator in JavaScript: Integer Cents, Rounding on Purpose and Currency Symbols That Don't Pretend to Convert

DEV Community: javascript·Abid Ali·about 18 hours ago
#u0no17c4
#devtojavascript#devto#dev#const#assert
Reading 0:00
15s threshold

A fee calculator looks like the easiest thing you can put on a website. Take an amount, subtract a percentage, subtract a withdrawal fee, print the result. I've built a few of these for Digital Dialogue, my freelancing blog, and every one of them was "three subtractions" for about an hour, until the numbers started coming out one cent wrong.

One cent sounds harmless. It isn't, for two reasons. People compare your number with the one in their payment history, and when it doesn't match they stop trusting everything else on the page. And a rate calculator that rounds the wrong way can tell someone to charge a rate that leaves them slightly short of the goal they typed in.

This post is the money layer I'd write today: integer cents, percentages as basis points, rounding you choose on purpose, a gross-up that never undershoots, and formatting that changes the symbol without pretending to convert anything. It's plain JavaScript with tests for Node's built-in runner.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.