View previous topic :: View next topic
|
Author |
Message |
mirco cadei
New User
Joined: 10 Jul 2008 Posts: 2 Location: milan, italy
|
|
|
|
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 |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
mirco cadei
New User
Joined: 10 Jul 2008 Posts: 2 Location: milan, italy
|
|
|
|
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 |
|
|
|