Hacker News new | ask | show | jobs
by thanatropism 3305 days ago
Money comes in integers. Any function that works with monetary values needs to eat integers and output integers.

This is not pedantry, it's a real-world constraint.

2 comments

I thought your "real-world constraint" existed too. Then I had to keep track of thousandths of a cent.

When you have experienced the "no, a cent is no longer granular enough" problem, the conversion of DECIMAL(7,2) to DECIMAL(9,4) and the attendant code compatibility is something you'll appreciate.

That's what fixed precision types are: integers + a scale factor -- whether it's cents, mils or something else.

Javascript does badly need a native fixed precision type beyond "everything is a double" or some web assembly hack.

And I like Javascript, but this is a real problem.