Reputation: 564
Im stuck on how to write a function which get as an input ether
and transform into a float.
The problem is when I transform into a FLOAT, it is missing characters.
#value= int(45264444.4444444444466666254188888888888526)
value= "45264444.4444444444466666254188888888888526"
float(value)
output:45264444.44444445
Upvotes: 1
Views: 380
Reputation: 8846
A float
can not store arbitrary numbers, its precision is limited.
A float
will store the few most significant digits of a number (in binary form), and discard the rest.
That is why you see the value truncated.
For a more in-depth look at the problem, see for example https://0.30000000000000004.com/, or some general guide on floating-point arithmetic.
Upvotes: 1