ROUND and TRUNC functions in SQL

For Complete YouTube Video: Click Here

In this class, we will understand ROUND and TRUNC functions in SQL.

We have already discussed the concepts of MOD POWER and SQRT functions.

ROUND and TRUNC functions in SQL

To understand this, we will consider the table as shown below.

ROUND and TRUNC functions in SQL 1
ROUND and TRUNC functions in SQL 1

TRUNC: Chops off the digits to the precession.

The syntax for TRUNCATE is as shown below.

TRUNC(Value, Precession)

To the TRUNC, the first parameter is the value or the column of values, and the second parameter is precession.

The number of digits that we want to use after the decimal point.

The use of TRUNC and its output is as shown below.

ROUND and TRUNC functions in SQL 2
ROUND and TRUNC functions 2

ROUND: Rounds the number to the given number of precession.

The syntax for ROUND is as shown below.

ROUND(Value, Precession)

The use of ROUND and the output is as shown below.

ROUND and TRUNC functions in SQL 3
ROUND and TRUNC functions in SQL 3

The difference between ROUND and TRUNC is that the value will get rounded to the nearest number in ROUND.

For example, consider the number 3.57895.

TRUNC(3.57895, 2) will remove all the digits after digits of the decimal point.

The output is 3.57.

ROUND(3.57895, 2) will round all the digits after digits of the decimal point.

The output is 3.58.