Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2005
    Posts
    127

    Unanswered: function to TRUNCATE a number to desired decimal places

    Could any body help in pointing out a function to truncate a number(may be whole number or a decimal) to desired decimal places in DB2.

    thanks,
    Mihir

  2. #2
    Join Date
    Feb 2005
    Location
    Bangalore,India
    Posts
    39
    Typecast to decimal datatype.

    decimal(expression,precision,scale)

    db2 values(decimal(123.345678,4,1))

    OUTPUT
    -------
    123.3

    FYI..Please read SQL Reference vol 1

    Thanks,

  3. #3
    Join Date
    Nov 2004
    Posts
    1,427
    Provided Answers: 4
    Use TRUNCATE(number, places)


    VALUES (
    TRUNC(873.726,2),
    TRUNC(873.726,1),
    TRUNC(873.726,0),
    TRUNC(873.726,-1),
    TRUNC(873.726,-2),
    TRUNC(873.726,-3) );

    returns 873.720, 873.700, 873.000, 870.000, 800.000, and 0.000.
    With kind regards . . . . . SQL Server 2000/2005/2012
    Wim

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

Posting Permissions

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