.NET does not have a type to represent monetary values. In general you will simply use Decimal
as it has the necessary accuracy. This has some limitations though:
- Without looking at surrounding code it is difficult to tell if a variable represents money or simply a large decimal value
- Currency information is not part of the type so it is possible to incorrectly mix monetary values in systems that support multiple currencies at once
- Displaying money requires that you use a format string to indicate the currency
There have been many implementations of money in .NET. This is my version. Please note that this code is new so bugs may exist. Additionally I’ve taken the requirements and implementation from my own needs. Your needs may differ so you may need to modify the code to behave differently for your applications.