C# Formatting Numeric String

Formatting Standard Numeric Format Strings
http://msdn.microsoft.com/en-us/library/s8s7t687(VS.80).aspx

Formatting Custom Numeric Format Strings
http://msdn.microsoft.com/en-us/library/0c899ak8.aspx

Formatting Numeric Format Strings (Alignment)
Integer    http://www.csharp-examples.net/string-format-int/
Double    http://www.csharp-examples.net/string-format-double/
DateTime http://www.csharp-examples.net/string-format-datetime/
Align String with Spaces  http://www.csharp-examples.net/align-string-with-spaces/
Indent String with Spaces http://www.csharp-examples.net/indent-string-with-spaces/
IFormatProvider               http://www.csharp-examples.net/iformatprovider-numbers/
Custom IFormatProvider   http://www.csharp-examples.net/custom-iformatprovider/






















































Character Description Examples Output
C or c Currency Console.Write(“{0:C}”, 2.5); $2.50
Console.Write(“{0:C}”, -2.5); ($2.50)
D or d Decimal Console.Write(“{0:D5}”, 25); 25
E or e Scientific Console.Write(“{0:E}”, 250000); 2.50E+05
F or f Fixed-point Console.Write(“{0:F2}”, 25); 25
Console.Write(“{0:F0}”, 25); 25
G or g General Console.Write(“{0:G}”, 2.5); 2.5
N or n Number Console.Write(“{0:N}”, 2500000); 2,500,000.00
X or x Hexadecimal Console.Write(“{0:X}”, 250); FA
Console.Write(“{0:X}”, 0xffff); FFFF

Leave a Reply

Your email address will not be published. Required fields are marked *