This code gives me the correct volume of a sphere:
public static double CalculateBallVolume(double aRadius)
{
double volume = (4.0 / 3.0) * Math.PI * Math.Pow(aRadius,3);
return volume;
}
but if I write it like this, I get a different result:
public static double CalculateBallVolume(double aRadius)
{
double volume = (4 / 3) * Math.PI * Math.Pow(aRadius,3);
return volume;
}
In particular, it appears that 4 / 3
does not give the same result as 4.0 / 3.0
. Why not?