double value format vs int value format : int format « Data Types « C# / C Sharp






double value format vs int value format

   

using System;
using System.Globalization;
using System.Threading;

public class NumericFormats
{
   public static void Main()
   {
      CultureInfo ci = new CultureInfo("en-us");

      double floating = 1234567.987654321;
      Console.WriteLine("C: {0}", floating.ToString("C", ci));           
      Console.WriteLine("E: {0}", floating.ToString("E03", ci));         
      Console.WriteLine("F: {0}", floating.ToString("F04", ci));         
      Console.WriteLine("G: {0}", floating.ToString("G", ci));           
      Console.WriteLine("N: {0}", floating.ToString("N03", ci));         
      Console.WriteLine("P: {0}", (floating/10000).ToString("P02", ci)); 
      Console.WriteLine("R: {0}", floating.ToString("R", ci));           

      // Output integral values
      int integral = 9999;
      Console.WriteLine("C: {0}", integral.ToString("C", ci));           
      Console.WriteLine("D: {0}", integral.ToString("D6", ci));          
      Console.WriteLine("E: {0}", integral.ToString("E03", ci));         
      Console.WriteLine("F: {0}", integral.ToString("F01", ci));         
      Console.WriteLine("G: {0}", integral.ToString("G", ci));           
      Console.WriteLine("N: {0}", integral.ToString("N01", ci));         
      Console.WriteLine("P: {0}", (integral/10000.0).ToString("P02", ci));
      Console.WriteLine("X: 0x{0}", integral.ToString("X", ci));          
   }
}

/*

C: $1,234,567.99
E: 1.235E+006
F: 1234567.9877
G: 1234567.98765432
N: 1,234,567.988
P: 12,345.68 %
R: 1234567.9876543209
C: $9,999.00
D: 009999
E: 9.999E+003
F: 9999.0
G: 9999
N: 9,999.0
P: 99.99 %
X: 0x270F


*/

   
    
    
  








Related examples in the same category

1.Format integer: C
2.Format integer with default formatting
3.Format integer with 3 digits and leading zeros
4.Format integer with 1 decimal digit
5.Format integer as hexadecimal
6.Format integer with eight hexadecimal digits
7.Format integer as octal and binary numbers
8.Use standard numeric format specifier: C
9.Use standard numeric format specifier: D8
10.Use standard numeric format specifier: E4
11.Use standard numeric format specifier: e3
12.Use standard numeric format specifier: F
13.Use standard numeric format specifier: N
14.Use standard numeric format specifier: P
15.Use standard numeric format specifier: X
16.Use standard numeric format specifier: 0,0.000
17.Use standard numeric format specifier: #,#.00#;(#,#.00#)
18.Int32.ToString (IFormatProvider)
19.Int32.ToString Method (String)
20.Int32.ToString Method (String, IFormatProvider)
21.Int32.ToString Converts the numeric value of this instance to its equivalent string representation.
22.Add Ordinal Suffix
23.Converts an integer into a roman numeral.