expect(floatNumber).toBeNear(number, epsilon)
See original GitHub issueCompare a given value numerically to be in the range of number-epsilon
and number+epsilon
. Thus epsilon
specifies the maximum tolerance the compared value is allowed to vary.
Example
expect(4.23223432434).toBeNear(4, 0.25); // success
expect(4.23223432434).toBeNear(4, 0.2); // failure
Implementation
Could internally use the “toBeWithinRange” matcher, but the above is much nicer to write if you’re not targeting a specific range, but just a value and allow some wobbling.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Number.EPSILON - JavaScript - MDN Web Docs
The Number.EPSILON property represents the difference between 1 and the smallest floating point number greater than 1.
Read more >What are the possible usage scenarios for Number.EPSILON?
EPSILON property represents the difference between 1 and the smallest floating point number greater than 1.
Read more >JavaScript Number EPSILON Property - GeeksforGeeks
EPSILON property is used to check whether floating-point numbers are equal or not. In this EPSILON is accessed by calling the Number as...
Read more >Avoid testing floating point numbers for equality - Appmarq
As long as this imprecision stays small, it can usually be ignored. However, it also means that numbers expected to be equal (e.g....
Read more >Number.EPSILON - JavaScript
EPSILON property represents the difference between 1 and the smallest ... object to access this static property (use Number. ... expected output: true....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
https://github.com/JamieMason/Jasmine-Matchers/pull/68 adds the
toBeNear()
matcher.Thanks @Nolanus, do I understand correctly that
is equivalent to