Format number: C, D9, E, F3, N, X, x : Number format « Data Type « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / CSharp Tutorial » Data Type » Number format 




using System;

class MainClass
{
  public static void Main(string[] args)
  {
    Console.WriteLine("C format: {0:C}"99989.987);
    Console.WriteLine("D9 format: {0:D9}"99999);
    Console.WriteLine("E format: {0:E}"99999.76543);
    Console.WriteLine("F3 format: {0:F3}"99999.9999);
    Console.WriteLine("N format: {0:N}"99999);
    Console.WriteLine("X format: {0:X}"99999);
    Console.WriteLine("x format: {0:x}"99999);

  }
}
C format: $99,989.99
D9 format: 000099999
E format: 9.999977E+004
F3 format: 100000.000
N format: 99,999.00
X format: 1869F
x format: 1869f














2.55.Number format
2.55.1.To format numeric data
2.55.2.Numeric Formatting: Decimal ({0:D}, {0:D7})
2.55.3.Numeric Formatting: Fixed-Point ({0:F}, {0:F0}, {0:F5})
2.55.4.Numeric Formatting: General ({0:G}, {0:G7}, {0:G4})
2.55.5.Numeric Formatting: Number ({0:N}, {0:N4})
2.55.6.Numeric Formatting: Scientific (Exponential) ({0:E}, {0:E10}, {0:e4})
2.55.7.Custom Numeric Formatting: Decimal Point ({0:#####.000}, {0:##.000})
2.55.8.Custom Numeric Formatting: Digit or Space Placeholder ({0:#####}, {0:###})
2.55.9.Custom Numeric Formatting: Digit or Zero Placeholder ({0:000})
2.55.10.Custom Numeric Formatting: Escapes and Literals ({0:###\\#})
2.55.11.Custom Numeric Formatting: Exponential Notation ({0:###.000E-00}, {0:#.0000000E+000})
2.55.12.Custom Numeric Formatting: Group Separator ({0:##,###}, {0:##,000.000})
2.55.13.Custom Numeric Formatting: Number Prescaler ({0:000,,,.###})
2.55.14.Custom Numeric Formatting: Percent Notation ({0:##.000%})
2.55.15.Custom Numeric Formatting: Section Separator ({0:###.00;0;(###.00)})
2.55.16.Format number: C, D9, E, F3, N, X, x
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.