Use ToString() to format doubles : Double Format : Data Type C# Examples


C# Examples » Data Type » Double Format »

 

Use ToString() to format doubles









    
using  System;  
  
class  MainClass  {  
    public  static  void  Main()  {  
        double  v  =  17688.65849;  
        double  v2  =  0.15;  
        int  x  =  21;  
    
        string  str  =  v.ToString("F2");  
        Console.WriteLine(str);  
  
        str  =  v.ToString("N5");  
        Console.WriteLine(str);  
  
        str  =  v.ToString("e");  
        Console.WriteLine(str);  
  
        str  =  v.ToString("r");  
        Console.WriteLine(str);  
  
        str  =  v2.ToString("p");  
        Console.WriteLine(str);  
  
        str  =  x.ToString("X");  
        Console.WriteLine(str);  
  
        str  =  x.ToString("D12");  
        Console.WriteLine(str);  
  
    }  
}
    
   
  
   



Output

17688.66
17,688.65849
1.768866e+004
17688.65849
15.00 %
15
000000000021


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Type
» Double Format