Mega Code Archive

 
Categories / C# Tutorial / Development
 

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