Use standard numeric formats in C#
You can use numeric formatting characters to display numbers in particular formats. These formats work with a variable's ToString method as well as with String.Format. For example, the code value.ToString("C") returns the variable value formatted as currency.
This example builds a ListView that demonstrates the various standard numeric formats. It then uses code from the example Make a program generate HTML table code for ListView data and display it in a WebBrowser control in C# to convert the results into the following HTML table.
See also:
Floating Point Formats | ||
---|---|---|
Name | Format | Result |
Currency | C or c | ($12,345.68) |
Exponential | E or e | -1.234568E+004 |
Fixed Point | F or f | -12345.68 |
General | G or g | -12345.6789 |
Number | N or n | -12,345.68 |
Percent | P or p | -1,234,567.89 % |
Round-trip | R or r | -12345.6789 |
Integer Formats | ||
Name | Format | Result |
Decimal | D or d | -123456789 |
Hexadecimal | H or h | F8A432EB |
Comments