Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

why db2 arithmetic division does not shows decimals ?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
mirco cadei

New User


Joined: 10 Jul 2008
Posts: 2
Location: milan, italy

PostPosted: Wed Sep 10, 2008 2:31 pm    Post subject: why db2 arithmetic division does not shows decimals ?
Reply with quote

Hello everybody,
I have a simple query (the main query is more complex but this little example is equivalent)

SELECT (11 / 2),
VALUE((11 / 2),.000000000000000000)
,(2 / 11),
VALUE((2 / 11),0.00)
FROM SYSIBM.SYSDUMMY1;

running the query gives this result

COL1 COL2 COL3 COL4
----------- -------------------------------- ----------- ----------------
5 5,000000000000000000 0 0,00

We have tried many formats and data conversion to ensure it's not just a "data format matter" but with no result.
Is there someone who would be so kind and help me reduce my deep ignorance ?
Thank you everybody and have a nice day/night.
Back to top
View user's profile Send private message

ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed Sep 10, 2008 3:40 pm    Post subject:
Reply with quote

Use CAST ....
Code:


SELECT CAST((11.0 / 2.0) AS DECIMAL(2,1))
FROM SYSIBM.SYSDUMMY1;



should give you 5.5 .... this is because DB2 doesnt know wht is the data type of your object value ...

Code:


SELECT CAST((2.0 / 11.0) AS DECIMAL(5,5))
FROM SYSIBM.SYSDUMMY1;



should give you .18181
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Wed Sep 10, 2008 3:41 pm    Post subject:
Reply with quote

being in italy, you probably use the comma as decimal, as germany does.

having access to a UK computer, decimal is decimal and my results are with '.' whereas yours are ','.

it is due to the installation of your db2 system.
Back to top
View user's profile Send private message
mirco cadei

New User


Joined: 10 Jul 2008
Posts: 2
Location: milan, italy

PostPosted: Wed Sep 10, 2008 5:27 pm    Post subject:
Reply with quote

Thank you very much !

I have also found another answer that suggested this way:
SELECT DEC(2 / (FLOAT(11)),11,6);
it works too.
Thanks again, have a nice day and kind regards.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 37 Tue Dec 06, 2016 8:04 pm
No new posts Identification Division anandgbe COBOL Programming 2 Sat May 28, 2016 11:51 am
No new posts Starts DEBUGGING by Procedure Divisio... jackare Testing & Performance analysis 4 Sun Jan 10, 2016 10:37 pm
No new posts DB2:: Division of an Integer Column b... GaganGarg DB2 15 Thu Jan 16, 2014 11:35 am
No new posts how to define decimals in cics map us... ram_vizag CICS 10 Tue Dec 03, 2013 4:01 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us