The ABS() function returns an absolute number, i.e., the positive value of a number. The data type of the returned value will depend on the data type of the value passed to the ABS() function.
The syntax for the ABS() function is as follows:
The ABS() function requires one argument:
- x: An expression that evaluates to a number.
ℹ️ The ABS() function will return the negation of the negative numbers.
The following example demonstrates how the ABS() function can be used to obtain the absolute value of a negative number:
It will return an absolute value of the passed argument:
The following example demonstrates how the ABS() function can be used with an expression to obtain the absolute value of the result:
The result of the above statement is -150. However, you will get the output 150, as 150 is the positive version of -150.
The following example demonstrates how the ABS() function can be used with a table to obtain the absolute values of all numbers in a specific column:
1) First, create a table named absTable containing an initialValue column with some positive and negative values:
2) Next, use the following query to find the absolute value of all numbers:
3) The above query will retrieve all values in the "initialValue" column and their absolute values in the "absoluteValue" column. The output will look something like this: