Maha

Maha

  • NA
  • 0
  • 327.8k

Binary Arithmetic Operators

May 4 2012 7:18 PM
In C# 7/100 result is 0 (not 0.07). But in the following program in the equation (tax = saleAmount * 7/100;) 7/100 is realized as 0.07. Please explain the reason.


using System;
public class UseSevenPercentSalesTax
{
public static void Main()
{
double myPurchase = 12.99;

ComputeSevenPercentSalesTax(myPurchase);//variable argument
ComputeSevenPercentSalesTax(35.67);//constant argument

double num = 7 / 100;

Console.WriteLine("num = {0}", num);

Console.ReadKey();
}

public static void ComputeSevenPercentSalesTax(double saleAmount)
{//saleAmount - local variable
double tax;

tax = saleAmount * 7/100;

Console.WriteLine("The tax on {0} is {1}", saleAmount, tax.ToString("f"));
}
}
/*
The tax on 12.99 is 0.91
The tax on 35.67 is 2.50
num = 0
*/


Answers (2)