Use the decimal type to compute a discount in CSharp
Description
The following code shows how to use the decimal type to compute a discount.
Example
using System; //from w ww . j a v a 2s.com
public class MainClass{
public static void Main() {
decimal price;
decimal discount;
decimal discounted_price;
// compute discounted price
price = 19.95m;
discount = 0.15m; // discount rate is 15%
discounted_price = price - ( price * discount);
Console.WriteLine("Discounted price: $" + discounted_price);
}
}
The code above generates the following result.