Format decimal to string in correct culture info

c00ke picture c00ke · Feb 26, 2010 · Viewed 18.2k times · Source

What is the best way to format a decimal amount to string for UI display in the correct culture info?

Answer

Hans Kesting picture Hans Kesting · Feb 26, 2010

Add a format to the ToString: myDecimal.ToString("#.00") or myDecimal.ToString("C").

For a nullable decimal (decimal?) you will need to use the .Value property (myNullableDecimal.Value.ToString("C")) or cast the value to a plain (non-nullable) decimal. Be sure not to do this when the value is null or you will get an exception!

See the documentation for Standard or Custom numeric format strings.