Syntax for format specifiers
Justification specifier
Positive numbers indicate right alignment, and negative numbers indicate left alignment. If the number of characters you want to represent is less than the number specified in the alignment specifier, a space is filled in, and if more, it is ignored.
1Staticvoid Main (String[] args) 2 {3 var temp = 1000; "|{ 0,10}| "5 Console.WriteLine ( | {0,-10}| "6 Console.WriteLine ( | {0,3}| "7}
Format field
1var temp =123.456789;2 Console.WriteLine ("{0:F3}", temp);//Fixed point, number of decimal digits reserved3 Console.WriteLine ("{0:C}", temp);//Represents currency, depending on the locale of the PC4 Console.WriteLine ("{0:D10}",123);//Decimal number5 Console.WriteLine ("{0:G4}", temp);//Keep "number Length" according to the specifier, and the last one rounded6 Console.WriteLine ("{0:X}",123);//Turn 16 binary (case sensitive)7 Console.WriteLine ("{0:N4}1234567,890123"; Span style= "color: #008000;" >// 8 Console.WriteLine ( "{0:p}", temp); // 9 Console.WriteLine ( "{0:r} //10 Console.WriteLine ( "{0:e3}// scientific notation (case-sensitive)
Formatting numeric strings