Sunday 22 October 2017

Round Vs Truncate

TRUNC and ROUND function looks similar but not exactly.

ROUND function used to round the number to the nearest but TRUNC used to truncate/delete the number from some position.

Syntax:

TRUNC(number, precision);
ROUND(number, precision);

Some cases both returns same result.

SQL> select trunc(25.67),round(25.67) from dual;

 TRUNC(25.67)    ROUND(25.67) 
2526

Below chart clearly explains the difference

 Input   TRUNC   ROUND  
25.67,02526
25.67,125.625.7
25.34,125.325.3
25.34,225.3425.34
25.67,-12030

No comments:

Post a Comment