MySQL TRUNCATE() Function

In MySQL, the TRUNCATE() function truncates a numbers to a specified number of decimal places.

The function simply truncates the decimal by the specified number of digits without rounding. If you want to round decimals, use the ROUND(). If you want to return the integer part of a number, use FLOOR(), CEIL(), or CEILING().

TRUNCATE() Syntax

Here is the syntax of MySQL TRUNCATE() function:

TRUNCATE(x, d)

Parameters

x
Required. processed numbers.
d
Required. Number of decimal places to retain.

Return value

In MySQL, the TRUNCATE() function returns a numbers truncated to a specified number of decimal places.

  • The TRUNCATE() function will return NULL if any parameter is NULL.

TRUNCATE() Examples

SELECT
    TRUNCATE(123.179, 1),
    TRUNCATE(123.179, 2),
    TRUNCATE(123.179, 4),
    TRUNCATE(123.179, 0),
    TRUNCATE(123.179, -1),
    TRUNCATE(123.179, -2),
    TRUNCATE(123.179, NULL)\G

output

*************************** 1\. row ***************************
   TRUNCATE(123.179, 1): 123.1
   TRUNCATE(123.179, 2): 123.17
   TRUNCATE(123.179, 4): 123.179
   TRUNCATE(123.179, 0): 123
  TRUNCATE(123.179, -1): 120
  TRUNCATE(123.179, -2): 100
TRUNCATE(123.179, NULL): NULL