Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2007
    Posts
    51

    Unanswered: 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)

  2. #2
    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
    Last edited by guyprzytula; 05-31-07 at 07:01.
    Best Regards, Guy Przytula
    DB2 UDB LUW certified V6/7/8

  3. #3
    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)

  4. #4
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •