IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

why db2 arithmetic division does not shows decimals ?


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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
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: 6966
Location: porcelain throne

PostPosted: Wed Sep 10, 2008 3:41 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Arithmetic division using Syncsort SYNCSORT 6
No new posts Help this REXX Rookie-Bad arithmetic ... CLIST & REXX 7
This topic is locked: you cannot edit posts or make replies. Assembler - Packed Decimals - PACK in... PL/I & Assembler 3
No new posts Bad arithmetic conversion when assign... CLIST & REXX 4
No new posts Procedure Division Section COBOL Programming 2
Search our Forums:

Back to Top