PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#option 1 using math.isclose
import math
if math.isclose(0.1 + 0.2, 0.3):
print(math.isclose(0.1 + 0.2, 0.3))
print("True")
else:
print("False")
#option 2 using round function takes the result of the addition and rounds it to 10 decimal places.
if round(0.1 + 0.2, 10) == 0.3:
print(round(0.1 + 0.2, 10))
print("True")
else:
print("False")
#option 3 using Decimal represent these numbers exactly as the decimal strings, without any initial conversion to binary floating-point
from decimal import Decimal
if Decimal('0.1') + Decimal('0.2') == Decimal('0.3'):
print(Decimal('0.1') + Decimal('0.2'))
print("True")
else:
print("False")
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run