What is the best data type to use for money in C#?

NotDan picture NotDan · Mar 28, 2009 · Viewed 287.8k times · Source

What is the best data type to use for money in C#?

Answer

Lee Treveil picture Lee Treveil · Mar 28, 2009

As it is described at decimal as:

The decimal keyword indicates a 128-bit data type. Compared to floating-point types, the decimal type has more precision and a smaller range, which makes it appropriate for financial and monetary calculations.

You can use a decimal as follows:

decimal myMoney = 300.5m;