top | item 41779381

(no title)

yett | 1 year ago

C# has a decimal type: "The decimal type is a 128-bit data type suitable for financial and monetary calculations." https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...

discuss

order

nsxwolf|1 year ago

That provides the basis for solving precision and rounding issues but for a money library you need more abstractions. The ability to assign a currency code and supply conversion rates and convert between currencies at a minimum.

epolanski|1 year ago

Also, avoid making errors like summing different currencies.

moomin|1 year ago

The thing is, it doesn’t really help. A system I’m working on can have hundreds of monetary amounts in the same currency. Storing the currency against each one is an awful waste of space.

Equally the allocation trick is good, but you’ll find that the people who really care about this stuff really care about the exact algorithm you’re using and who it favours.

tightbookkeeper|1 year ago

That’s an application design choice, not a minimum. An alternative is to work internally in one unit and convert at format time.