Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Money is an interesting case. The basic units are clear, with most modern currencies having a 3-letter code, and a decimal subdivision of the main unit into 100 or 1,000 subunits (or 10^8 satoshis :) Calculations should usually use integer arithmetic in the subunit, with Bankers Rounding.

Historically, there were non-decimal currencies, like British pounds-shilling-pence, with 1:20:12 ratio.

However, each value also needs a timestamp to enable conversions between currencies, or comparisons for the same currency at different times (inflation).



Money is not like a unit in a system of units that has fixed relationships. It's not only time-varying but also contextual in other ways, eg. by locale, by financial status or any number of other factors. This is a good analysis of how to represent money so that you can perform arithmetic and check for equality while accounting for contextual conversions:

https://deque.blog/2017/08/17/a-study-of-4-money-class-desig...


What if there are multiple exchange rates with every person having different access to them?


Then there are 2 currencies with an exchange rate and transaction fees to convert between them. The black market currency represents the true value whereas the local currency is based on price controls.

Eg https://en.wikipedia.org/wiki/Venezuelan_bol%C3%ADvar#Curren...


A timestamp is not enough. You need the exact market from which you get the price, too.


> Calculations should usually use integer arithmetic in the subunit

On a computer, for specific purposes. It's a reasonable way to implement certain computations correctly, but has little to do with the topic.


On the contrary, because every currency amount can be expressed as an integer multiple of the lowest denomination, the currency has an intrinsic integer structure


Not in the case of interest. Banks store fractional amounts that only gets rounded when paying or invoicing it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: