If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > decimals in query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-31-07, 04:30
annamaria annamaria is offline
Registered User
 
Join Date: Apr 2007
Posts: 51
decimals in query

I have two fields whose format in the table is decimal (14,5).
I now have to divide one field by the other, and I want the result
to be in the format decimal (21,16).
Whatever I do I'm not able to get this result with sixteen decimals.
I tried with dec(Field1,21,16)/Field2 but it yields six decimals.
I tried with dec(Field1,21,16)/Field2 but it yields an integer.
I tried other ways but I always get a result which is made of maximum
six decimals.
What can I do?
Thank you.
Anna - Verona (Italy)
Reply With Quote
  #2 (permalink)  
Old 05-31-07, 05:58
guyprzytula guyprzytula is offline
Registered User
 
Join Date: Jun 2006
Posts: 471
I tried on a sample table and get anyhow more digits - see sample
[11:49 AM][db2admin]/cygdrive/c/workdir:db2 "create table xx (col1 dec(14,5),col2 dec(14,5))"
DB20000I The SQL command completed successfully.
[11:49 AM][db2admin]/cygdrive/c/workdir:db2 insert into xx values "(12.99991,3.33333)"
DB20000I The SQL command completed successfully.
[11:50 AM][db2admin]/cygdrive/c/workdir:db2 "select * from xx"

COL1 COL2
---------------- ----------------
12,99991 3,33333

1 record(s) selected.

[11:50 AM][db2admin]/cygdrive/c/workdir:
[11:51 AM][db2admin]/cygdrive/c/workdir:db2 "select col1/col2 from xx"

1
---------------------------------
3,89997689997689997

1 record(s) selected.
and even this worked :
[11:55 AM][db2admin]/cygdrive/c/workdir:db2 "select cast(col1/col2 as dec(25,18)) from xx"

1
---------------------------
3,899976899976899970

Best Regards, Guy Przytula
__________________
Best Regards, Guy Przytula
DB2 UDB LUW certified V6/7/8

Last edited by guyprzytula; 05-31-07 at 06:01.
Reply With Quote
  #3 (permalink)  
Old 05-31-07, 06:24
annamaria annamaria is offline
Registered User
 
Join Date: Apr 2007
Posts: 51
Now what I think is that the columns I select have some kind of rigid format in the table, and therefore they can't be easily changed into other formats.
Maybe Stolze could have an idea of what's happening here.
I'm waiting for other suggestions.
Thank you.
Anna - Verona (Italy)
Reply With Quote
  #4 (permalink)  
Old 05-31-07, 11:14
annamaria annamaria is offline
Registered User
 
Join Date: Apr 2007
Posts: 51
I managed to solve the problem: first I changed the format to float, then
made the division and then changed the format to decimal.
Thank you.
Anna
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On