format number in C#
Possible Duplicate:
.NET String.Format() to add commas in thousands place for a number
How to format a number 1234567 into 1,234,567 in C#?
For format options for Int32.ToString(), see here or here.
For example:
string s = myIntValue.ToString("#,##0");
The same format options can be use in a String.Format, as in
string s = String.Format("the number {0:#,##0}!", myIntValue);
var decimalValue = 1234567m;
var value = String.Format("{0:N}", decimalValue); // 1,234,567.00
或没有分
var value = String.Format("{0:N0}", decimalValue); // 1,234,567
Using your current locale's thousands separator:
int n = 1234567 ;
n.ToString("N0");
Or, use the overload to ToString, which takes the culture as a parameter.
链接地址: http://www.djcxy.com/p/50540.html下一篇: 格式编号在C#中