Comment

Comment by SideburnsOfDoom

The recommendation that "developers should use integers to represent money" (with an implicit 2 decimal places, that will work for many but not all currencies) is not a great one.

If your language has a dedicated type for monetary amounts, use that. (1)

If it does not, but you can make a value object to represent, e.g. amount and currency code, then do that.

If however, your language does not have a dedicated type for monetary amounts, or one cannot be trivially built or retrieved as a package (2), then you should ask yourself if it is really a suitable language for financial tasks.

1) https://learn.microsoft.com/en-us/dotnet/api/system.decimal

2) https://github.com/shopspring/decimal https://www.npmjs.com/package/ts-money

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton