Mysql Abs Function

MySQL: ABS Function

This tutorial explains how to use the MySQL ABS function with syntax and examples.

Description

The MySQL ABS function returns the absolute value of a number.

Syntax

The syntax for the ABS function in MySQL is:

ABS( number )

Parameters or Arguments

number

The number to convert to an absolute value.

Applies To

The ABS function can be used in the following versions of MySQL:

  • 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 MySQL ABS function examples and explore how to use the ABS function in MySQL.

For example:

mysql> SELECT ABS(-23);
Output: 23

mysql> SELECT ABS(-23.6);
Output: 23.6

mysql> SELECT ABS(-23.65);
Output: 23.65

mysql> SELECT ABS(23.65);
Output: 23.65

mysql> SELECT ABS(30 * -1);
Output: 30