What is the difference trunc() and round() functions in T-SQL

  • TRUNC() and ROUND() function are almost same but,
  • ROUND() function used to round the number to the nearest value.
  • TRUNC() used to truncate/delete the number from some position.
  • Some cases both returns same result.

Example:

SQL> select round(55.65) from dual;   // next nearest integer value.

Output:  56

SQL> select round(55.45) from dual;   // previous nearest integer value.

Output:  55

  • If the decimal part grater than >50 you will get next integer value.
  • If the decimal part less than  <=50 you will get previous integer value.

SQL>select trunc(56.75)

Output: 56

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

TRUNC(25.67)    ROUND(25.67)
————                      ————
25                                    26

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s