Teradata SQL - Round Numbers to Hundreds or Thousands

access_time 4 months ago visibility38 comment 0

The following code snippets show how to use round numbers to hundreds or thousands in Teradata. 

warning Alert - The following code snippets are used to round to the smallest hundreds or thousands that is equal or greater than the input number. 

FLOOR and CEILING functions

In Teradata, there are two functions that are commonly used beside ROUND function:

  • CEILING: Returns the smallest integer value that is not less than the input argument.

  • FLOOR: Returns the largest integer equal to or less than the input argument.

Examples

select floor(100123.23)
select ceiling(100123.23)

The output will be 100123.00 and 100124.00 respectively.

We will use CEILING function to implement. 

Round up to hundreds using CEILING function

select ceiling(ceiling(100123.23)/100.00)*100;
select ceiling(ceiling(100123)/100.00)*100;
select ceiling(ceiling(100103)/100.00)*100;
select ceiling(ceiling(100003)/100.00)*100;
select ceiling(ceiling(100000.001)/100.00)*100;

The result is 100,200 for the first three statements and 100,100 for the last two statements.

Round up to thousands using CEILING function

select ceiling(ceiling(100123.23)/1000.000)*1000;
select ceiling(ceiling(100123)/1000.000)*1000;
select ceiling(ceiling(100003)/1000.000)*1000;
select ceiling(ceiling(100000.0003)/1000.000)*1000;

The result is: 101,000.

info Last modified by Administrator at 2 months ago copyright This page is subject to Site terms.
Like this article?
Share on

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

Kontext Column

Created for everyone to publish data, programming and cloud related articles.
Follow three steps to create your columns.


Learn more arrow_forward

More from Kontext

local_offer teradata local_offer SQL local_offer teradata-sql-query

visibility 386
thumb_up 0
access_time 12 months ago

In different databases, the syntax of selecting top N records are slightly different. They may also differ from ISO standards.

local_offer teradata local_offer SQL local_offer teradata-sql-query

visibility 386
thumb_up 0
access_time 12 months ago

In different databases, the syntax of selecting top N records are slightly different. They may also differ from ISO standards.

local_offer teradata local_offer SQL local_offer teradata-sql-query

visibility 3177
thumb_up 0
access_time 4 years ago

For many SQL Server or Oracle developers, you may encounter some inconveniences when writing SQL queries. For example, how to select from dummy table or local defined variables. This page summarize the equivalents in Teradata SQL.

About column

Code snippets and tips for various programming languages/frameworks.

rss_feed Subscribe RSS