Hacker News new | ask | show | jobs
by hortense 894 days ago
To store dollars with a precision of 1 cent, you store into your integers cents instead of dollars. No need to mess with anything more complicated.
2 comments

>To store dollars with a precision of 1 cent, you store into your integers cents instead of dollars. No need to mess with anything more complicated.

As someone who does it, financial math is often done at a precision of more than 1 cent. This is the reason that most (high-latency) financial libraries use strings underneath.

This al doesn't address the high order floating point arithmetic of geo-spacial, which was the Patriot issue.

To store dollars with a precision of 1 billionth of a cent, you store into your integers 1 billionth of cents instead of dollars.
Gas is sold in 9/10th of a cent fraction. What now?
To store dollars with a precision of 1/10 cent, you store into your integers 1/10 cents instead of dollars.