What data type to use for representing currency in C# and Sql Server 2005/2008?

ASP.NET, SQL Server Add comments

This post will be short and sweet.  What data type should you use to represent currencies in C#? – Decimal

If you use double, you will end up with rounding errors on more precise numbers, and if you are writing applications that support multiple currencies, namely currencies that use very large numbers, such as the Indonesia Rupiah ($1 = 9,345.8 Indonesian Rupiahs) you will also get doubles represented in scientific notation when they reach very large values (think trillions).

In C# use Decimal

Now for SQL Server 2005/2008 I believe the best practice would be to use the money datatype if you are dealing exclusively with U.S. dollars, otherwise you should use decimal to get more precise values.

About

My name is Brent Krueger and I am an ASP.Net web application developer and designer in Madison, WI. I enjoy doing web design and development for charitable organizations, as well as businesses. I also like to post any solutions I may find to irritating development problems that I may run into on a daily basis.

2 Responses to “What data type to use for representing currency in C# and Sql Server 2005/2008?”

  1. Delorse Pooni Says:

    Hey there, I think you most likely are able to help me. I have a MSSQL .ldf and .mdf file which I have to restore. Any opinions on how to do this? Regards

  2. Brent Says:

    You should be able to attach an MDF file Delorse. Have you tried Googling this? There should be plenty of detailed instructions out there. Good luck!

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in