Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

A System.Double should be compared to the number 0 or an integer by using the Double.Equals() method or by subtracting the number from the Double and comparing the absolute value of the difference to a small tolerance value to account for rounding errors. For example:

// using Double.Equals() double num1 = 0.0; double num2 = 1.234567; if (Double.Equals(num1, num2)) { Console.WriteLine("The numbers are equal"); }

// using tolerance value double num3 = 3.0; int num4 = 3; double tol = 0.0001; if (Math.Abs(num3 - num4) < tol) { Console.WriteLine("The numbers are equal"); }