Use ToString() to format values : Number Format : Development Class C# Source Code


Custom Search

C# Source Code » Development Class » Number Format »

 

Use ToString() to format values









    

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/


// Use ToString() to format values. 
 
using System; 
 
public class ToStringDemo { 
  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); 
 
    str = 189.99.ToString("C"); 
    Console.WriteLine(str); 
  } 
}

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Development Class
» Number Format