MySQL ABS() Function
The ABS()
function in MySQL calculates the absolute value of a number. The absolute value of a number is its distance from zero, always resulting in a non-negative value.
ABS(): Definition and Usage
ABS()
is a simple but useful mathematical function. It's frequently used to remove the sign (positive or negative) from a number, ensuring that you are working with only the magnitude of the value. This is commonly needed in calculations or comparisons where the sign is not relevant.
Syntax
Syntax
ABS(number)
Parameter Values
Parameter | Description |
---|---|
number |
The number for which you want to find the absolute value. This is a required numeric value. |
Example
Calculating the Absolute Value
This example shows how to use the ABS()
function to get the absolute value of -243.5.
Syntax
SELECT ABS(-243.5);
Output
243.5