w3resource logo


>SQLite abs function

SQLite abs() function

Secondary Nav

Description

SQLite abs() function returns the absolute value of a number.

  • The abs(X) function returns the absolute value of the numeric argument X. Abs(X) returns NULL if X is NULL.
  • abs(X) return 0.0 if X is a string or blob that cannot be converted to a numeric value.
  • If X is the integer -9223372036854775808 then abs(X) throws an integer overflow error since there is no equivalent positive 64-bit two complement value.

Syntax

abs(X)

Argument

Name Description
X A number whose absolute value is to be retrieved.

Example: SQLite abs() function

The following SQLite statement will return the absolute value of a positive number specified in the argument.

sqlite> SELECT abs(5);

Here is the result.

abs(5)
----------
5

Example: SQLite abs() function using negative value

The following SQLite statement will return the absolute value of a negative number defined in the argument.

sqlite> SELECT abs(-5);

Here is the result.

abs(-5)
----------
5


Join our Question Answer community to learn and share your programming knowledge.

Solve these problems:

Java: How to convert a string to an integer in Java?

C#: Loops in c#

SQL: JOIN using more than 5 tables