method
test.Matchers.toBeCloseTo
expected: number,
numDigits?: number
): void;
Asserts that a value is close to the expected value, within floating point precision.
For example, the following fails because arithmetic on decimal (base 10) values often has rounding errors in limited precision binary (base 2) representation.
@param expected
the expected value
@param numDigits
the number of digits to check after the decimal point. Default is 2
expect(0.2 + 0.1).toBe(0.3); // fails
Use `toBeCloseTo` to compare floating point numbers for approximate equality.