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

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

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.

By | 2011-04-06T22:51:19+00:00 April 6th, 2011|Categories: ASP.NET, SQL Server|Tags: , , |2 Comments

About the Author:

2 Comments

  1. Delorse Pooni March 8, 2012 at 9:09 pm - Reply

    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

    • Brent March 11, 2012 at 9:08 pm - Reply

      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 Comment