Add comma thousand separator to decimal (.net)

maxp picture maxp · Oct 19, 2009 · Viewed 45.8k times · Source

I have a decimal number, say 1234.500.

I want to display it as 1,234.5.

I'm currently converting it to a double to remove the trailing '0's.

string.Format("{0:0,0}",1234.500) removes the decimal place, and other formatting options seem to use two decimal places regardless.

Can anyone offer insight?

Answer

Henk Holterman picture Henk Holterman · Oct 19, 2009

You should use a custom formatting like #,##0.00

string s = string.Format("{0:#,##0.00}", xx);

Will produce 1,234.50 when xx = 1234.5M
forget about converting to double, that won't really help.