I’m using this code to calculate the area of a triangle, with the values 2, 2 and 1. When I do the calculation in my pocket calculator I get 0.97, but in C# it’s 0. I guess it has something to do about the rounding of the decimals, but I have changed the last value from i and up, but still get 0 as the result! What am I doing wrong? Help preciated! Thanks!
double i = (valueA + valueB + valueC) / 2;
return Math.Round(Math.Sqrt(i * (i - valueA) * (i - valueB) * (i - valueC)),1);
Divide by
2.0or2dor2DReason: Integer Division gives only integer part and removes the fraction part.
2is integer.2.0is double value.OR
OR
Second line remains the same