Python, mysql, floating point values question

Christopher Kang chris.kang.83 at gmail.com
Fri Jul 1 18:40:19 EDT 2005


I had a question about python and mysql, but I want to first thank
those who taught me about the factory method, it was exactly what I
needed.

Anyway, I have a problem where I am pulling floating point values out
of mysql and into python using the MYSQLdb module.

However, the values seem to be altered a little when I store them in python.

Because the decimal places are off, I am unable to use the values that
I have in order to write a sql statement (again using the MYSQLdb)
that pulls column values from just that single value i'm looking for.

Let me explain more clearly:

Let's say I pull column1 values for all records, and they happen to be:

1.4, 1.5632, 1.32523 in the mysql database.

Now I realize that I am interested in all the column values for just
the 1.5632 record.  Unfortunately, python seems to be taking the
floating point values, and doing something with it, such that my
variable has something like 1.5632000000001 stored in it or such.

I thus, can't pull the value out using a sql statement such as
"Select * from table_name where column1 = my_variable_value" becuase
my_variable_value has 1.563200000000001 stored in it, and not 1.5632.

The way that the variable gets adjusted seems to be random.

Is there a solution to this?



Thank you very much!



More information about the Python-list mailing list