logoalt Hacker News

sieve • today at 1:00 PM • 1 reply • view on HN

Accounting has the concept of materiality. But you still want the figures to tally to the last cent.

One way to do this is to separate the computation/storage and presentation layer: use integers to store values as cents for computation/storage and only convert to dollars+cents on display. But then someone might suddenly demand three digits after the decimal point and you cannot go about changing every stored value just because the logic changed in one part of the application. So, using decimals is the safer choice.

I prefer integers for my plain text ledger software though because the format is in my control.


Replies

hansvm • today at 2:33 PM

I like using rational types for that sort of thing.