MySQL: TRUNCATE Function

  • Post author:
  • Post category:MySQL
  • Post comments:1 Comment
MySQL TRUNCATE Function

In this guide, we will explain how to use the MySQL TRUNCATE function with syntax and examples.

Description

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

Syntax

The syntax for the TRUNCATE function in MySQL is:

TRUNCATE( number, decimal_places )

Parameters or Arguments

numberThe number to truncate.decimal_placesThe 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 ROUNDCEILCEILING, and FLOOR functions.

Applies To

The TRUNCATE function can be used in the following versions :

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

Example

Let’s look at some TRUNCATE function examples and explore how to use the TRUNCATE function.

For example:

mysql> SELECT TRUNCATE(125.315, 0);
Result: 125

mysql> SELECT TRUNCATE(125.315, 1);
Result: 125.3

mysql> SELECT TRUNCATE(125.315, 2);
Result: 125.31

mysql> SELECT TRUNCATE(125.315, -1);
Result: 120

mysql> SELECT TRUNCATE(125.315, -2);
Result: 100

mysql> SELECT TRUNCATE(-125.315, 0);
Result: -125

Learn More : Click Here

This Post Has One Comment

Leave a Reply