Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2003
    Posts
    7

    Unanswered: Is there a database level setting for rounding decimal?

    DB2 by default truncates the decimal values to the field precision setting. Is there a database level setting to make this round the value rather than truncate?

    Thanks for your help.

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Would the ROUND() function work for you?
    ---
    "It does not work" is not a valid problem statement.

  3. #3
    Join Date
    Sep 2003
    Posts
    7
    I am aware of the ROUND function, I am looking for a database wide setting. My application is used on multiple databases and hence if I use the ROUND then I have to have database specific code in many places.

    So, I am looking for a database wide setting if there is one.

    Thanks for your reply.

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    No there is not. Is there such setting in other "mutliple databases"? I doubt that...
    ---
    "It does not work" is not a valid problem statement.

  5. #5
    Join Date
    Sep 2004
    Location
    Belgium
    Posts
    1,126
    Quote Originally Posted by makonahalli
    If I use ROUND() then I have to have database specific code in many places.

    So, I am looking for a database wide setting if there is one.
    There is an easy way to implement the ROUND function yourself, in a database wide way, and moreover without the overhead of a scalar function call:

    1. Round a positive expression (expr) to the nearest integer value:
    Code:
    CAST(expr + 0.5 AS integer)
    (Or just INT(expr + 0.5) .)

    2. Round a positive expression (expr) to the nearest multiple of 0.01:
    Code:
    CAST(expr + 0.005 AS decimal(18, 2))
    3. Round any (positive or negative) expression to the nearest integer:
    Code:
    case when expr > 0 then CAST(expr+0.5 AS int) else CAST(expr-0.5 AS int) end
    --_Peter Vanroose,
    __IBM Certified Database Administrator, DB2 9 for z/OS
    __IBM Certified Application Developer
    __ABIS Training and Consulting
    __http://www.abis.be/

Posting Permissions

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