Select Page

Art of BI: C# Convert Decimal to String

Author: Christian Screen | 1 min read | July 13, 2009

Microsoft usually has good documentation but on this particular topic, I always felt that it was lacking. Here is the MS core documentation for converting a decimal to a string, http://msdn.microsoft.com/en-us/library/59095yyw.aspx.

I recently needed to ensure that I was only getting only two decimal places on a dollar amount as I converted it into a string and was going to write a nice long post myself and then I found this really nice post over at csharp-examples (view post).

Mainly I was looking for the following syntax just to ensure that I was setting up things correctly:

// just two decimal places
String.Format("{0:0.00}", 123.4567); // "123.46"
String.Format("{0:0.00}", 123.4); // "123.40"
String.Format("{0:0.00}", 123.0); // "123.00"

They have some other great custom formatting items as well. Check ’em out.

Subscribe to Our Blog

Never miss a post! Stay up to date with the latest database, application and analytics tips and news. Delivered in a handy bi-weekly update straight to your inbox. You can unsubscribe at any time.