int str = 1236;MessageBox.Show("E=" + str.ToString("E"));
MessageBox.Show("C=" + str.ToString("C"));
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHByZSBjbGFzcz0 = "brush: java;"> MessageBox. Show ("D5 =" + str. ToString ("D5 "));
MessageBox.Show("F2=" + str.ToString("F2"));
MessageBox.Show("G2=" + str.ToString("G2"));
MessageBox.Show("N=" + str.ToString("N"));
MessageBox.Show("{0:N}=" + string.Format("{0:N}", str));
1. Separate the numbers with semicolons and specify the digits after the decimal point
String. Format ("{0: N}", 14200): 14,200.00 (default: two digits after the decimal point)
String. Format ("{0: N3}", 14200.2458): 14,200.246 (Auto rounding)
2. Formatting percentage
String. Format ("{0: P}", 0.24583): 24.58% (two decimal places in the percentage are reserved by default)
String. Format ("{0: P1}", 0.24583): 24.6% (Auto rounding)
Note:
String. Format: replaces each Format item in the specified String type with the text equivalent item of the value of the corresponding object.
Format rules. Format: "{N [, M] [: formatString]}", arg1 ,... ArgN, in this format:
1) N is an integer starting from 0, indicating the number of parameters to be formatted
2) M is an optional integer that represents the width of the formatted parameter. If M is a negative number, the formatted value is left aligned. If M is a positive number, the formatted value is right aligned.
3) formatString is another optional parameter, indicating the format code.
ArgN indicates the expression to be formatted, which corresponds to N.
If argN is null, it is replaced by an empty string. If no formatString exists, use the ToString method corresponding to parameter N to format it.