int.tostring (format):
The format string takes the form Axx, where a is the format specifier, specifies the format type, XX is the precision specifier, and controls the number of significant digits or decimal places for the formatted output, as follows:
Format specifier
Description |
Example |
Output |
C |
Currency |
2.5.ToString ("C") |
¥2.50 |
D |
Decimal number |
25.ToString ("D5") |
00025 |
E |
Scientific type |
25000.ToString ("E") |
2.500000E+005 |
F |
Fixed point |
25.ToString ("F2") |
25.00 |
G |
Conventional |
2.5.ToString ("G") |
2.5 |
N |
Digital |
2500000.ToString ("N") |
2,500,000.00 |
P |
Percentage |
|
|
X |
Hexadecimal |
255.ToString ("X") |
Ff |
to use formatting in String.Format:
These structural objects can also be formatted in the String.Format method, which is contained between "{}" and separated by ":". ":" is preceded by the String.Format index value, as is the general format, and ":" is followed by the format type of these structures. If you use placeholders, you use the "," split with the index, a positive number to the right, and a negative to the left, and the absolute value represents the width of the characters, for example:
String. Format ("The value is {0,7:f3}", 123.45);
The result is: " 123.2"
//Where: 7 represents a placeholder (right-aligned), occupies 7 digits, and if use-7 is left-aligned, occupies seven digits.
Format character description
0 decimal left integer decimal right placeholder
# non-0 o'clock digit placeholder
. Decimal point
, Thousand separator
% multiplied by 100 plus% to indicate
\ escape Sequence
' String
"" String
; Split positive numbers and 0
format string data type value output
##### Double 123 123
00000 Double 123 00123
(###) ###-Double 1234567890 (123) 456–7890
#.## Double 1.2 1.2
0.00 Double 1.2 1.20
00.00 Double 1.2 01.20
#,# Double 1234567890 1,234,567,890
#,, Double 1234567890 1235
#,,, Double 1234567890 1
#,# #0, Double 1234567890 1,235
#0. ##% Double 0.086 8.6%
0.## #E +0 Double 86000 8.6E+4
0.## #E +000 Double 86000 8.6E+004
0.## #E -000 Double 86000 8.6E004
[##-##-##] Double 123456 [12-34-56]
# #;(# #) Double 1234 1234
# #;(# #) Double-1234 (1234)