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.

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

The example program displays a similar table in a ListView control.

See also:

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.