Rounding issue - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Rounding issue (/thread-35195.html) |
Rounding issue - kmll - Oct-08-2021 I am writing a simple program to calculate the zero point for a function. However it will never find it because of rounding. Any suggestions of how this can be done? Thanks. def function_g(x): return ((2*x)-1) counter=-10 while counter<10: functionvalue=funksjon_g(counter) if functionvalue==0 : print("Zero point is ----------------> " + str(counter)) print("counter is " + str(counter) +" "+ str(function_g(counter))) counter=counter+0.1 RE: Rounding issue - Yoriz - Oct-08-2021 Use https://docs.python.org/3/library/math.html#math.isclose Wrote:math.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0) |