Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Thu, 29 Jun 2006 @ 20:52:52 GMT


     
  <Prev Next>   <<First <Prev
Next>
Last>>
 


Subj:   Re: Decimal rounding
 
From:   McLeod, Terry

In chapter 3, "Decimal/Numeric Data Types", of the Teradata Database v2r6.0 manual entitled "SQL Reference - Data Types and Literals", there is a discussion beginning on page 77 of how rounding works. In particular, pertaining to your question, it first defines "the rounding digit" as the last digit position that will be retained in your rounded value. If the digit to the right of the rounding digit is > 5, then it rounds up. If the value to the right of the rounding digit is < 5, it rounds down. When the digit to the right of the rounding digit is exactly 5 (your case), the logic is as follows:

First, if there are other non-zero digits beyond the first digit to the right of the round digit, then, of course, it rounds up. But when the digit to the right of the rounding digit is exactly 5 AND there are no other digits further to the right (as is the case in both of your examples), then rounding is guided by the DBSControl Record "RoundHalfwayMagUp" Flag. If this flag is set to FALSE, then if the rounding digit itself is ODD, it will be rounded up and if the rounding digit itself is EVEN, then it will not change. -- This is why your 6.75 becomes 6.8 while your 6.85 remains at 6.8.

If the "RoundHalfwayMagUp" Flag is set to TRUE, then rounding in the case of a "halfway value" (5) will always be "away from zero". Although examples of this last bit aren't provided, I read it to say that 6.75 will round to 6.8, and 6.85 will round to 6.9. In addition, -6.75 will round to -6.8 (further "away from zero") and -6.85 will round to -6.9.

I note that the book does say of the latter: "While this is the most common rounding semantics for business applications, it is also non- trivially biased in the upwards direction.".

To learn about the DBSControl Record, the reader is referred to the UTILITIES book.


Hope this helps.

Terry M. McLeod



     
  <Prev Next>   <<First <Prev
Next>
Last>>
 
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023