Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home3/bbminfoc/public_html/Server/DB/Connection.php on line 93
MySQL abs Math Function - Absolute Value
BBMINFO Tutor

MySQL Math Function - abs()

Description & Uses of MySQL abs()

The MySQL abs() function is used to return the absolute value or modulus |x| of a real number x is the non-negative value of x without regard to its sign.

Formula

|x| = √x2 ⇒ √-32 = 3

where x = -3

Simple Example - MySQL abs(number);

MySQL Input Screen

Plain text
SELECT ABS(0) AS `Absolute Value`; -- Integer Value
SELECT ABS(-3) AS `Absolute Value`; -- Negative Value
SELECT ABS(-2.53) AS `Absolute Value`; -- Float Value

MySQL Output Screen

0
3
2.53

MySQL abs - Absolute value in other languages

Simple MySQL Syntax

  1. abs(number);

Parameter & Return Type

mixed number It may be either integer or float
Return Returns an number respective to an input (int, long, short, float, decimal)

Example #1 Integer Values - MySQL abs(number);

MySQL Input Screen

Plain text
-- Absoulte Value - Positive Integer Values
SELECT ABS(6) AS `Absolute Value`;
SELECT ABS(0) AS `Absolute Value`;
 
-- Absoulte Value - Negative Integer Values
SELECT ABS(-3) AS `Absolute Value`;
SELECT ABS(-0) AS `Absolute Value`;

MySQL Output Screen

6
0
3
0

Example #2 Float Values - MySQL abs(number);

MySQL Input Screen

Plain text
-- Absoulte Value - Positive Float Values
SELECT ABS(3,14) AS `Absolute Value`;
SELECT ABS(0.00) AS `Absolute Value`;
 
-- Absoulte Value - Negative Float Values
SELECT ABS(-0.56) AS `Absolute Value`;
SELECT ABS(-0.00) AS `Absolute Value`;

MySQL Output Screen

3.14
0
0.56
0