Use the C format specifier to output dollars and cents. : Console Output Format « Development « C# / CSharp Tutorial






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);  
  }     
}
Discounted price: $16.96








14.4.Console Output Format
14.4.1.Format: Allignment
14.4.2.Format: Currency
14.4.3.Format: {0,-10:G}
14.4.4.Format: {0,-10}
14.4.5.Format: {0,-10:F4} -- Fixed Point, 4 decimal places
14.4.6.Format: {0,-10:C} -- Currency
14.4.7.Format: {0,-10:E3} -- Sci. Notation, 3 dec places
14.4.8.Format: {0,-10:x} -- Hexadecimal integer
14.4.9.Use format commands: indicate the parameter sequence
14.4.10.Use the C format specifier to output dollars and cents.
14.4.11.Format double value
14.4.12.Numeric formatting specifiers
14.4.13.Display 4 mandatory and 3 optional arguments using the Console.WriteLine method.