0

Error

if 0.1+0.2==0.3: print("True") else: print("False") #output: False #explain plz

3rd Mar 2025, 4:31 PM
Ravi Anand
Ravi Anand - avatar
2 Respuestas
+ 3
In most programming languages including Python, floating-point values are stored in the IEEE 754 format. This format represents numbers in binary. In binary, these floating-point numbers don't have an exact representation. Think of it as 10/3, the result is something like 3.3333... it doesn't have an exact representation. For instance, 0.1 in binary isn't actually just 0.100000.. it's 0.000110011... and it's the same case with 0.2. So when you add the values together, the result is something like 0.3000004, which is not equal to exactly 0.3.
3rd Mar 2025, 4:47 PM
Afnan Irtesum Chowdhury
Afnan Irtesum Chowdhury - avatar
3rd Mar 2025, 7:50 PM
BroFar
BroFar - avatar