473,387 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

question about cx_Oracle .thanks

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
Jul 18 '05 #1
7 1874
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
Jul 18 '05 #2
David Fraser <da****@sjsoft.com> wrote in message news:<cb**********@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?
Jul 18 '05 #3

"coolmenu" <me******@yahoo.com.cn> wrote in message
news:a6**************************@posting.google.c om...
David Fraser <da****@sjsoft.com> wrote in message

news:<cb**********@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
Jul 18 '05 #4
Paul Watson wrote:
"coolmenu" <me******@yahoo.com.cn> wrote in message
news:a6**************************@posting.google.c om...
David Fraser <da****@sjsoft.com> wrote in message


news:<cb**********@ctb-nnrp2.saix.net>...
coolmenu wrote:
[...]>>>tuple=curobj.fetchone()
>>>tuple

(42505.660000000003)

why 42505.66---->42505.6600000000003??? [...]

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

And, in fact, more generally, see:

http://www.python.org/doc/faq/genera...-so-inaccurate

which you will (I hope) appreciate does not just apply to Python. Python
is confusing you by showing you the contents of your tuple as accurately
as possible: your computer actually stores 4205.66 as 42505.660000000003
- this is an accurate decimal representation of the binary value:
print repr(42055.66)

42055.660000000003

Even more confusingly, when you try it on a SPARC processor you may get
slightly different answers. Wise programmers always round monetary
calculations at every step along the way[1].

regards
Steve

[1] Yes, I know this is a simplification, please let's not have yet
another repeat of the eternal thread. Allow some room for pedagogy here!
Jul 18 '05 #5
Steve Holden wrote:
which you will (I hope) appreciate does not just apply to Python. Python
is confusing you by showing you the contents of your tuple as accurately
as possible: your computer actually stores 4205.66 as 42505.660000000003
Or, more precisely, it stores it as the binary number represented
here by these hexadecimal digits (shown here in big-endian format):
binascii.hexlify(struct.pack('>d', 42055.66)) '40e488f51eb851ec'

Since it has a limited number of binary digits available, it can't
store precisely 42055.66, so 42055.6600000whatever is the next
closest. To demonstrate, the nearest neighbours that can be
represented accurately are these (binary value one higher or lower):
struct.unpack('>d', binascii.unhexlify('40e488f51eb851ed')) (42055.660000000011,) struct.unpack('>d', binascii.unhexlify('40e488f51eb851eb'))
(42055.659999999996,)

So clearly the binary can capture only increments of about
0.000000000007 or 0.000000000008 at a time, and all of these
values must be treated as approximations... unless one was
trying to store 42055.660000000003 in the first place!
- this is an accurate decimal representation of the binary value:
>>> print repr(42055.66)

42055.660000000003


All very true. ;-)

-Peter
Jul 18 '05 #6
Peter Hansen wrote:
[...]
Since it has a limited number of binary digits available, it can't
store precisely 42055.66, so 42055.6600000whatever is the next
closest. To demonstrate, the nearest neighbours that can be
represented accurately are these (binary value one higher or lower):
>>> struct.unpack('>d', binascii.unhexlify('40e488f51eb851ed')) (42055.660000000011,) >>> struct.unpack('>d', binascii.unhexlify('40e488f51eb851eb')) (42055.659999999996,)

So clearly the binary can capture only increments of about
0.000000000007 or 0.000000000008 at a time, and all of these
values must be treated as approximations... unless one was
trying to store 42055.660000000003 in the first place!

Just to make things even more complicated, of course, we must also
remember that the delta between two adjacent floating-point numbers
isn't constant, but will vary according to the magnitude of the numbers.
- this is an accurate decimal representation of the binary value:
>>> print repr(42055.66)

42055.660000000003

All very true. ;-)

And it just goes to show that floating-point is quite confusing enough
to make many a beginner run away in fright!

regards
Steve

Jul 18 '05 #7
Thanks all;-)

but how can i select number from oracle?
Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: GrayGeek | last post by:
After cx_Oracle and the related Oracle tools for Python 2.2.3 + Boa-constructor on Win2000, I added "import cx_Oracle" to the top of a test script. It gives me an error about being unable to find...
1
by: Greg Lindstrom | last post by:
Hello - I am trying to connect to an Oracle database on an HP-9000 via Python 2.3 and cx_Oracle. I have set the following in my python routine: os.putenv('ORACLE_HOME', '/u01/app/oracle')...
1
by: jmdeschamps | last post by:
Hello Having cx_Oracle (an Oracle database connector for Python) used it here where I teach for the last couple of years, and finding it so easy to use (and install) I was taken aback when I got...
4
by: infidel | last post by:
I have a stored procedure that has a single output parameter. Why do I have to pass it a string big enough to hold the value it is to receive? Why can't I pass an empty string or None? >>>...
1
by: lblr33 | last post by:
I downloaded cx_Oracle from http://www.cxtools.net/default.aspx?nav=cxorlb and selected the windows installer for Oracle 8i, Python 2.4 >From the readme.txt file: BINARY INSTALL: Place the...
4
by: MooMaster | last post by:
After some google searching on the forum I couldn't find any topics that seemed to relate exactly to my problem, so hopefully someone can help me out... I'm running python 2.4.1 on a local Win2K...
4
by: Richard Schulman | last post by:
I'm having trouble getting started using Python's cx_Oracle binding to Oracle XE. In forthcoming programs, I need to set variables within sql statements based on values read in from flat files. But...
7
by: Carl K | last post by:
I am trying to use this: http://python.net/crew/atuining/cx_Oracle/html/cx_Oracle.html it is a real module, right? sudo easy_install cx_Oracle did not easy_install cx_Oracle. ...
3
by: Benjamin Hell | last post by:
Hi! I have a problem with the cx_Oracle module (Oracle database access): On a computer with cx_Oracle version 4.1 (Python 2.4.3, Oracle 10g) I can get query results consisting of strings...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.