Saturday 12 January 2019

python - Compare approximate value to 6 decimal





I would like to ask how we can define a and b are actually same after approximation. I like to have True in the following case.



a = 59.9999999
b = 60.0000001
if (a==b):
print(True)

else:
print(False)

Answer



a = 59.9999999
b = 60.0000001
np.isclose([a],[b],atol =a-b)
#op
array([ True])


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...