In Python, how can I check if a floating point number is approximately a whole number, with a user-specified maximum difference?
I am thinking of something like is_whole(f, eps)
, where f
is the value in question and eps
is the allowed maximum deviation, with the following results:
>>> is_whole(1.1, 0.05)
False
>>> is_whole(1.1, 0.2)
True
>>> is_whole(-2.0001, 0.01)
True