Putting Commas in a Decimal
IF i have the following:
MyString.ValueType = typeof(System.Decimal);
how can i make this have an outp开发者_StackOverflowut of decimals with commas? In other words, instead of seeing 1234.5, i'd like to see 1,234.5
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".
精彩评论