SQL TRUNCATE Vs ROUND Function

In this session, we'll go over what is TRUNCATE and ROUND functions , as well as the differences between them.


SQL TRUNCATE Function

The TRUNC function cuts it off at the specified digits.

It's used to truncate a number to the amount of decimal places you choose.

TRUNCATE() does not round a number.

it just removes the decimal places that the user does not require.

Example 1: Consider the following example to truncate the given number

Select TRUNCATE(7.65342,3) As 'Get 3 number after decimal';

TRUNCATE() just removes the last decimal places, leaving only the first two decimal places, and returns 7.65 as 3the result.

Output: The output of truncate function is

Get 3 number after deciaml
7.653

SQL ROUND

If specified, the SQL ROUND() function is used to round an integer to a specified number of decimal places.

Assume that the salary value in the employee table for ename='Exforsys' is 55.666.

The ROUND() method returns a value X that has been rounded to the nearest integer.

If D is specified as a second argument, the function returns X rounded to D decimal places.

All digits to the right of the decimal point will be eliminated if D is negative.

Example: Let's round the following query to the nearest tenth:324.456. Using the query below, we may do so.

The number 324.456 is round after 2 decimal places

SELECT ROUND(324.456, 2) AS RoundValue;

Output: The Output of above query is

RoundValue
324.460

SQL Differnce Between TRUNCATE And ROUND FUNCTION

Main distinguish in truncate vs round function points are tabulated . :-

TRUNCATE ROUND
TRUNC() is a function that truncates or deletes a number from a specific location. The ROUND() function is used to round an integer to the nearest decimal place.
TRUNC() returns an integer with a specified number of decimal places truncated. As a result, it always chooses the lower value. The ROUND() function rounds a numeric field to the supplied number of decimals.
Truncate , which rounds up or down towards zero. ROUND() in the direction of negative infinity.