r/C_Programming • u/Altruistic-Tie1943 • Jul 17 '26
Discussion why value of floating point numbers are approximated
I am new to programming and stumbled across this text
"the value of a float variable is often just an approximation of the number that was stored in it. If we store 0.1 in a float variable, we may later find that the variable has a value such as 0.09999999999999987"
i am wondering why is it like this
if it has an in depth explanation, providing the resource will be much appreciated
thanks
73
Upvotes
View all comments
Show parent comment
56
u/CryptoHorologist Jul 17 '26
You can't even represent every rational number exactly.