What is the use of MySQL TRUNCATE() function?


MySQL TRUNCATE() function is used to return the value of X truncated to D number of decimal places. If D is 0, then the decimal point is removed. If D is negative, then D number of values in the integer part of the value is truncated. Its syntax can be as follows −

Syntax

TRUNCATE(X, D)

Here 

  • X is a number which is to be truncated.
  • D is the number up to which decimal places the number X has to be truncated.

Example

In the example below, it will truncate the given number up to 2 decimal places.

mysql> Select TRUNCATE(10.7336432,2);
+-----------------------+
| TRUNCATE(10.736432,2) |
+-----------------------+
|                 10.73 |
+-----------------------+
1 row in set (0.00 sec)

Updated on: 20-Jun-2020

89 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements