# Rounding | Data Types and Literals | Teradata Vantage - 17.10 - Rounding - Advanced SQL Engine - Teradata Database

## Teradata Vantage™ - Data Types and Literals

Product
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1143-171K
Language
English (United States)

## Rounding DECIMAL/NUMERIC Data Types

If a value being inserted does not fit into a DECIMAL or NUMERIC column, the value is rounded. SQL Engine rounds using the digit to the right of the rounding digit, the last digit that fits into the DECIMAL/NUMERIC field.

IF the value of the digit to the right of the rounding digit is … THEN the value of the rounding digit …
< 5 does not change.
> 5 increases by one.

Additional considerations come into play when the value of the digit to the right of the rounding digit is exactly five. One consideration is the value of the DBS Control Record RoundHalfwayMagUp field.

When the DBS Control Record RoundHalfwayMagUp field is set to FALSE, then rounding is performed as explained in the following table. This is the default.

IF the value of the digit to the right of the rounding digit is exactly 5 and … THEN ...
there are no trailing nonzero digits
• If the value of the rounding digit is odd, then the value of the rounding digit increases by one.
• If the value of the rounding digit is even, then the value of the rounding digit does not change.
there are trailing nonzero digits rounding behaves as if the value of the digit to the right of the rounding digit is greater than five.

The following table shows the results of inserting values into a DECIMAL(3,2) column.

WHEN the value of the INSERT is … THEN the value is rounded … Because the value of the digit to the right of the rounding digit is … AND the result is …
.014 down < 5 .01
.015 up 5 and last stored position is odd .02
.0151 up > 5 .02
.024 down < 5 .02
.025 down 5 and last stored position is even. .02
.0251 up > 5 .03

When the DBS Control Record RoundHalfwayMagUp field is set to TRUE, then the magnitude of all halfway values, both negative and positive, is rounded up, away from zero (see the illustration). While this is the most common rounding semantics for business applications, it is also nontrivially biased in the upward direction.