Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Putting Commas in a Decimal

Tags:

c#

IF i have the following:

MyString.ValueType = typeof(System.Decimal);

how can i make this have an output of decimals with commas? In other words, instead of seeing 1234.5, i'd like to see 1,234.5

like image 906
yeahumok Avatar asked Mar 04 '10 18:03

yeahumok


People also ask

Do British people use commas for decimals?

Great Britain and the United States are two of the few places in the world that use a period to indicate the decimal place. Many other countries use a comma instead. The decimal separator is also called the radix character.


1 Answers

Use:

String output = MyString.ValueType.ToString("N");

The "N" format specifier will put in the thousands separators (,). For details, see Decimal.ToString(string).

Edit:

The above will use your current culture settings, so the thousands separators will depend on the current locale. However, if you want it to always use comma, and period for the decimal separator, you can do:

String output = MyString.ValueType.ToString("N", CultureInfo.InvariantCulture);

That will force it to use the InvariantCulture, which uses comma for thousands and period for decimal separation, which means you'll always see "1,234.5".

like image 170
Reed Copsey Avatar answered Nov 03 '22 00:11

Reed Copsey