question about cx_Oracle .thanks

Paul Watson pwatson at redlinepy.com
Fri Jun 25 12:58:06 CEST 2004


"coolmenu" <menucool at yahoo.com.cn> wrote in message
news:a6a2957e.0406250233.402c2ddd at posting.google.com...
> David Fraser <davidf at sjsoft.com> wrote in message
news:<cbghcs$5m3$1 at ctb-nnrp2.saix.net>...
> > coolmenu wrote:
> > > Hi
> > >   i hava a db ORACLE 10G,a table valid_card
> > > (card_no,varchar2(10),now_balance number (12,2))
> > >
> > >  its'some record in table ('7188','42055.66')
> > >
> > >  i use cx_Oracle to select now_balance from table
> > >
> > >   curobj.execute("select loan_amount from valid_card where
> > > card_no='7181930166881974'");
> > > [<NumberVar object at 0x013A6920>]
> > >
> > >>>>tuple=curobj.fetchone()
> > >>>>tuple
> > >
> > > (42505.660000000003)
> > >
> > > why 42505.66---->42505.6600000000003???
> > > thanks
> >
> > This is because of the conversion of the float to decimal. Float objects
> > have limited accuracy. I don't think it's much to do with cx_Oracle
> >
> > David
>
>
> Can someone give me a advice? how can i do?
> donnt select number from oracle?

This has nothing to do with Oracle.  This is the problem of representing
floating point numbers on a binary system.  You may need to format the
number for presentation.

>>> x = 42055.66
>>> x
42055.660000000003
>>> print "the answer is %.2f" % (x)
the answer is 42055.66





More information about the Python-list mailing list