string to float, putting in list/tuple

Daniel Barié daniel0603 at me-barie.de
Mon Oct 14 15:14:39 EDT 2002


Hello,

when programming in Python, I stumbled over the following:
Let's assume, I've got four strings, Sl = '0.03169', SS31 = '-3.01',
SS41 = '-3.01'.

Now I want to convert these to float, using the builtin float()
function. The results are quite as expected: float(Sl) = 0.03169,
float(SS31) = -3.01, float(SS41) = -3.01.

But when stuffing a list with these floats the result is not as I
expect it to be:
[0.031690000000000003, -3.0099999999999998, -3.0099999999999998]

What happened?

Cheers,
Daniel Barié

P. S.:
Python 2.2 (#1, Apr 12 2002, 15:29:57)
[GCC 2.96 20000731 (Red Hat Linux 7.2 2.96-109)] on linux2




More information about the Python-list mailing list