Use the C format specifier to output dollars and cents. : Console Output Format : Development C# Examples


C# Examples » Development » Console Output Format »

 

Use the C format specifier to output dollars and cents.









    
using  System;    
    
class  Example  {          
    public  static  void  Main()  {          
        decimal  price;    
        decimal  discount;  
        decimal  discounted_price;    
    
        price  =  19.95m;    
        discount  =  0.15m;
  
        discounted_price  =  price  -  (  price  *  discount);    
    
        Console.WriteLine("Discounted  price:  {0:C}",  discounted_price);    
    }          
}
    
   
  
   



Output

Discounted price: $16.96


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Development
» Console Output Format