Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Posts
    107

    Unanswered: CHAR --> DECIMAL --> CHAR conversion

    I want to convert a CHAR value to DECIMAL and then add some numeric value to it and then convert it back to CHAR.

    While converting the decimal value into CHAR, it appends 0's to the left side of the value to make the converted CHAR size to 18 characters. How can i avoid this??? I don't want those 0's..

    see this test code:
    db2 select char(decimal('0')+1) from sysibm.sysdummy1

    1
    ------------------
    0000000000000001.

    1 record(s) selected.

    Thanks in advance & hope to hear your feedback.

    Jake

  2. #2
    Join Date
    Feb 2004
    Posts
    21
    Quote Originally Posted by Jake K
    I want to convert a CHAR value to DECIMAL and then add some numeric value to it and then convert it back to CHAR.

    While converting the decimal value into CHAR, it appends 0's to the left side of the value to make the converted CHAR size to 18 characters. How can i avoid this??? I don't want those 0's..

    see this test code:
    db2 select char(decimal('0')+1) from sysibm.sysdummy1

    1
    ------------------
    0000000000000001.

    1 record(s) selected.

    Thanks in advance & hope to hear your feedback.

    Jake
    HI,
    you can use substr.

  3. #3
    Join Date
    Aug 2004
    Posts
    330
    Use the precision-integer and scale-integer options of the DECIMAL function to specifiy the precision and scale of the result. (You will still get zeroes, just less of them) OR You could use LTRIM to remove zeroes from the resulting string, but if the result is 0000000000000000 you get nothing.

  4. #4
    Join Date
    Sep 2004
    Posts
    4
    Try
    select cast(char(cast(decimal(c1)+1 as decimal(1))) as char) from sysibm.sysdummy1

    Dakshinamurthi

Posting Permissions

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