Mega Code Archive

 
Categories / C# Tutorial / Data Type
 

Use the decimal type to compute a discount

using System;      class UseDecimal {        public static void Main() {          decimal price;       decimal discount;      decimal discounted_price;          price = 19.95m;       discount = 0.25m; // discount rate is 25%        discounted_price = price - ( price * discount);          Console.WriteLine("Discounted price: $" + discounted_price);     }  } Discounted price: $14.9625