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.
The following table shows the standard numeric format characters.
The example program displays a similar table in a ListView control.
See also:
Floating Point Formats | ||
---|---|---|
Name | Format Character | Example |
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 Character | Example |
Decimal | D or d | -123456789 |
Hexadecimal | H or h | F8A432EB |
- Use the DateTime class's standard formatting methods in C#
- Use custom date and time formats in C#
- Use custom numeric formats in C#
- Use standard date and time formats in C#
- Use standard numeric formats in C#
- Use standard numeric formats in C# (earlier version)
Comments