If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Is there a database level setting for rounding decimal?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-05-07, 15:38
makonahalli makonahalli is offline
Registered User
 
Join Date: Sep 2003
Posts: 7
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.
Reply With Quote
  #2 (permalink)  
Old 01-05-07, 17:27
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Would the ROUND() function work for you?
Reply With Quote
  #3 (permalink)  
Old 01-05-07, 19:26
makonahalli makonahalli is offline
Registered User
 
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.
Reply With Quote
  #4 (permalink)  
Old 01-05-07, 20:51
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
No there is not. Is there such setting in other "mutliple databases"? I doubt that...
Reply With Quote
  #5 (permalink)  
Old 01-07-07, 08:07
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
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/
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On