MariaDB TRUNCATE() Function
In MariaDB, TRUNCATE()
is a built-in numeric function that truncates a given number to a given decimal places.
MariaDB TRUNCATE()
Syntax
Here is the syntax of the MariaDB TRUNCATE()
function:
TRUNCATE(x, d)
Parameters
x
-
Required. The numbers being processed.
d
-
Required. The number of decimal places to keep.
If you provide the wrong number of parameters, MariaDB will report an error: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' 3)' at line 1
.
Return value
The MariaDB TRUNCATE()
function returns a number with the gaven decimal places.
MariaDB TRUNCATE()
Examples
This statement shows the basic usage of the MariaDB TRUNCATE()
function:
SELECT
TRUNCATE(123.456, 1),
TRUNCATE(123.456, 2),
TRUNCATE(123.456, 4),
TRUNCATE(123.456, 0),
TRUNCATE(123.456, -1),
TRUNCATE(123.456, -2),
TRUNCATE(123.456, NULL)\G
Output:
TRUNCATE(123.456, 1): 123.4
TRUNCATE(123.456, 2): 123.45
TRUNCATE(123.456, 4): 123.4560
TRUNCATE(123.456, 0): 123
TRUNCATE(123.456, -1): 120
TRUNCATE(123.456, -2): 100
TRUNCATE(123.456, NULL): NULL
Conclusion
In MariaDB, TRUNCATE()
is a built-in numeric function that truncates a given number to a given decimal places.