Format double with generla form and culture specific: G : double format « Data Types « C# / C Sharp






Format double with generla form and culture specific: G

  

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
        double number;
        
        number = 12345.6789;      
        Console.WriteLine(number.ToString("G", CultureInfo.InvariantCulture));
        Console.WriteLine(number.ToString("G", CultureInfo.CreateSpecificCulture("fr-FR")));
        Console.WriteLine(number.ToString("G7", CultureInfo.InvariantCulture));
        
        
        number = .0000023;
        Console.WriteLine(number.ToString("G", CultureInfo.InvariantCulture));
        Console.WriteLine(number.ToString("G", CultureInfo.CreateSpecificCulture("fr-FR")));
        
        
        number = .0023;
        Console.WriteLine(number.ToString("G", CultureInfo.InvariantCulture));
        
        number = 1234;
        Console.WriteLine(number.ToString("G2", CultureInfo.InvariantCulture));
        
        number = Math.PI;
        Console.WriteLine(number.ToString("G5", CultureInfo.InvariantCulture));

   }
}
/*
12345.6789
12345,6789
12345.68
2.3E-06
2,3E-06
0.0023
1.2E+03
3.1416
*/

   
    
  








Related examples in the same category

1.double format: padding zeros
2.double format: padding zeros and Culture sensitive
3.double format: decimal points padding
4.format double by specified culture
5.Custom double value format
6.format double value with decimal
7.double value to string with #
8.double value to string with #,##0,,
9.double value to percentage
10.Adding unicode format string to the result
11.double value to exponential formal
12.Escape the format specifiers
13.Condition based format
14.Convert double value to a phone number like format
15.Adding custom string to the format
16.Exponential double value literal
17.Parse string to double value
18.Standard format: C
19.Standard format: E04
20.Standard format: F
21.Standard format: N
22.Standard format: P
23.Converts double to string with ToString method
24.Parse console input value to double
25.Format integer: X
26.DateTime format: D
27.DateTime format: %M
28.decimal format: C3
29.Format a double value to currency and control the width
30.Format integer with D
31.Format double with E: exponential
32.Format integer with float points
33.Format double with decimal points: F
34.Format double value with N and specific culture
35.Format double value to its percentage form
36.Format double value: r
37.Format integer: X, X8, X2
38.Convert double to string using the culture-specific format information.
39.Convert double type value in exponential form to string using the culture-specific format information.
40.Converts double to string using the specified format.
41.Converts double to string using the specified format and culture-specific format information.
42.Custom number format: 0000
43.Custom number format: 0.00, 00.00
44.Custome number format: #,#
45.Custom number format: #.## (1)
46.Custom format: #####
47.Custom number format: [##-##-##] (2)
48.Custom number format: (###) ###-#### (3)
49.Custom number format: #0.##%, 0.###E+0
50.Custom number format: #,##0
51.Custom number format: #,,, (4)
52.Custom number format: #0.##% (5)
53.Custom number format: dollar notation
54.Custom number format:0.###E-000
55.Custom number format: escape # (6)
56.Custom number format: escape \
57.Custom number format:My Number = #
58.Custom number format: ##;(##);**AAA**
59.Use standard numeric format specifiers to format double value