Use the decimal type to compute a discount. : Decimal Calculation : Data Type C# Examples


C# Examples » Data Type » Decimal Calculation »

 

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);    
    }  
}
    
   
  
   



Output

Discounted price: $14.9625


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Type
» Decimal Calculation