totn MariaDB Functions

MariaDB: TRUNCATE Function

This MariaDB tutorial explains how to use the MariaDB TRUNCATE function with syntax and examples.

Description

The MariaDB TRUNCATE function returns a number truncated to a certain number of decimal places.

Syntax

The syntax for the TRUNCATE function in MariaDB is:

TRUNCATE( number, decimal_places )

Parameters or Arguments

number
The number to truncate.
decimal_places
The number of decimal places truncate to. This value must be a positive or negative integer.

Note

  • If decimal_places is a negative number, the TRUNCATE function will make digits to the left of the decimal place 0 values.
  • See also the ROUND, CEIL, CEILING, and FLOOR functions.

Applies To

The TRUNCATE function can be used in the following versions of MariaDB:

  • MariaDB 10

Example

Let's look at some MariaDB TRUNCATE function examples and explore how to use the TRUNCATE function in MariaDB.

For example:

SELECT TRUNCATE(85.253, 0);
Result: 85

SELECT TRUNCATE(85.253, 1);
Result: 85.2

SELECT TRUNCATE(85.253, 2);
Result: 85.25

SELECT TRUNCATE(85.253, -1);
Result: 80

SELECT TRUNCATE(-85.253, 0);
Result: -85