Rounding Number

Database

Rounding Number

How to Rounding up to the full number.

For example I have a duration 1.9585, I want to show it as 2. If I have duration as 4.3505, I want to show it as 5.

And I am using Teradata 13, CEIL Function is not supporting in that version :(

4 REPLIES
Enthusiast

Re: Rounding Number

Hi,

SEL CAST('1.985' as DECIMAL(10,0)

If you try to cast it to Decimal, it will round the value. I am not sure of CEIL function.

Thanks & Regards,

Adharssh.

Enthusiast

Re: Rounding Number

The one mentioned by Adarsh will work in the first case but not in the second case.sel cast(4.3505 as decimal(10,0)) gives the result as 4. Any casting you do like this with less than 0.5 will point to the preceding number and greater than that will point to the next number. but if you want to resort to 4+ to point to 5 then you need to use case statment.

Enthusiast

Re: Rounding Number

SEL CASE  WHEN COL1 - CAST (COL1 AS DECIMAL(10,0)) = 0 THEN COL1
ELSE CAST(COL1 AS DECIMAL(10,0)) + 1
END

You are right, the CEIL and FLOOR functions are available in TD 14.

Teradata Employee

Re: Rounding Number

Or the programmer's trick: cast((col1+.5) AS integer)

(cast to integer truncates the decimal portion)