VeloDB Cloud
SQL Manual
Functions
math-functions
truncate

truncate

Description

Syntax:

DOUBLE truncate(DOUBLE x, INT d)

This function truncates x according to the number of decimal places d.

The rules are as follows: If d > 0: keep d decimal places of x. If d = 0: retain the integer part of x only. If d < 0: retain the integer part of x only, and replace d digit places in the integer part with o .

Example

mysql> select truncate(124.3867, 2);
+-----------------------+
| truncate(124.3867, 2) |
+-----------------------+
|                124.38 |
+-----------------------+
mysql> select truncate(124.3867, 0);
+-----------------------+
| truncate(124.3867, 0) |
+-----------------------+
|                   124 |
+-----------------------+
mysql> select truncate(-124.3867, -2);
+-------------------------+
| truncate(-124.3867, -2) |
+-------------------------+
|                    -100 |
+-------------------------+

Keywords

TRUNCATE