This tutorial explains how to use the MySQL TRUNCATE function with syntax and examples.
The MySQL TRUNCATE function returns a number truncated to a certain number of decimal places.
The syntax for the TRUNCATE function in MySQL is:
TRUNCATE( number, decimal_places )
The number to truncate.
The number of decimal places truncate to. This value must be a positive or negative integer.
The TRUNCATE function can be used in the following versions of MySQL:
Let's look at some MySQL TRUNCATE function examples and explore how to use the TRUNCATE function in MySQL.
For example:
mysql> SELECT TRUNCATE(125.315, 0);
Output: 125
mysql> SELECT TRUNCATE(125.315, 1);
Output: 125.3
mysql> SELECT TRUNCATE(125.315, 2);
Output: 125.31
mysql> SELECT TRUNCATE(125.315, -1);
Output: 120
mysql> SELECT TRUNCATE(125.315, -2);
Output: 100
mysql> SELECT TRUNCATE(-125.315, 0);
Output: -125