tags:

views:

2931

answers:

9

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

+10  A: 

System.Decimal

The Decimal value type represents decimal numbers ranging from positive 79,228,162,514,264,337,593,543,950,335 to negative 79,228,162,514,264,337,593,543,950,335. The Decimal value type is appropriate for financial calculations requiring large numbers of significant integral and fractional digits and no round-off errors. The Decimal type does not eliminate the need for rounding. Rather, it minimizes errors due to rounding.

David Walschots
+18  A: 

decimal

Lee Treveil
+2  A: 

Decimal. If you choose double you're leaving yourself open to rounding errors

SquidScareMe
How do you not with Decimal?
Jess
+2  A: 

decimal has a smaller range, but greater precision - so you don't lose all those pennies over time!

Full details here:

http://msdn.microsoft.com/en-us/library/364x0z75.aspx

dommer
+1  A: 

You might find answers from this post helpful.

gugulethun
+8  A: 

Use the Money design patterns from Patterns of Enterprise Application Architecture; specify amount as decimal and the currency as an enum.

lmsasu
I was actually going to suggest this, but I make Currency a class so I can define an exchange rate (in relation to a "base currency", often the US dollar [which I set to have an exchange rate of 1.00]).
Thomas Owens
http://www.codeproject.com/KB/recipes/MoneyTypeForCLR.aspx
Hainesy
+1  A: 

Create your own class. This seems odd, but a .Net type is inadequate to cover different currencies.

Noel Kennedy
+2  A: 

Agree with the Money pattern: Handling currencies is just too cumbersome when you use decimals.

If you create a Currency-class, you can then put all the logic relating to money there, including a correct ToString()-method, more control of parsing values and better control of divisions.

Also, with a Currency class, there is no chance of unintentionally mixing money up with other data.

Lennaert
A: 

Always decimal ... please decimal.. believe me.. always. sincere recommendation..regards.andy

Andy