ABS()

Function Description

ABS(X) returns the absolute value of X, or NULL if X is NULL.

Function Syntax

Text
> ABS(number)

Parameter definition

Parameters

Description

number

Required parameters, any numerical data type can be taken

The return value type is consistent with the input type.

Example

Text
drop table if exists t1;
create table t1(a int,b float);
insert into t1 values(1,-3.1416);
insert into t1 values(-1,1.57);

mysql> select abs(a),abs(b) from t1;
+--------+--------------------+
| abs(a) | abs(b)             |
+--------+--------------------+
| 1      | 3.1415998935699463 |
| 1      | 1.5700000524520874 |
+--------+--------------------+
2 rows in set (0.01 sec)
Last updated on