below code is weird. when i debug it, i can see both "result" and "round" are 5, but output is "false". Any idea?
double result = Math.Log (243, 3); // 5
double round = Math.Round (result); // 5
Console.WriteLine (result == round);
below code is weird. when i debug it, i can see both "result" and "round" are 5, but output is "false". Any idea?
double result = Math.Log (243, 3); // 5
double round = Math.Round (result); // 5
Console.WriteLine (result == round);
Comparison of floating point with equality operator could have loss of precision while rounding values. You can fix this by compare a difference with epsilon. Use a Tolerance
like this:
Console.WriteLine(Math.Abs(result - round) < 0.0000001); // True