Floating point -compare using round
- round
x = 0.1 + 0.2
y = 0.3
print(x) # 0.30000000000000004
print(y) # 0.3
print(round(x, 10))
if round(x, 10) == round(y, 10):
print("They are equal")
else:
print("They are NOT equal")
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
x = 0.1 + 0.2
y = 0.3
print(x) # 0.30000000000000004
print(y) # 0.3
print(round(x, 10))
if round(x, 10) == round(y, 10):
print("They are equal")
else:
print("They are NOT equal")