Menu

SQLite Math Functions

SQLite offers numeric functions for rounding, truncation, powers, roots, and logarithms. Start with the operation you need rather than assuming similarly named functions behave the same way across SQL databases.

Choose the right rounding function

Function Behavior Example
round(X, Y) Round to Y decimal places (default 0) round(2.7) = 3.0
trunc(X) Remove the fractional part, toward zero trunc(2.7) = 2.0
ceil(X) Round upward to an integer ceil(2.7) = 3.0
floor(X) Round downward to an integer floor(2.7) = 2.0

round(X, -1) does not round to tens in SQLite: negative precision is treated as zero. For fixed-width numeric text, use printf() instead of round().

Other math operations

Use abs() for absolute values, sqrt() for square roots, and pow() for powers. The SQLite math functions documentation explains other functions and their availability.

round() is a core SQLite function. Some other functions, including ceil(), floor(), and sqrt(), require SQLite to be built with SQLITE_ENABLE_MATH_FUNCTIONS. Check your application’s SQLite build before relying on them.

Try the SQL examples in SQLite Playground, which runs SQLite locally in your browser.

  1. abs

    The SQLite abs() function returns the absolute value of the value specified by the parameter.
  2. acos

    The SQLite acos() function returns the arc cosine of the specified number.
  3. acosh

    The SQLite acosh() function returns the inverse hyperbolic cosine of a specified number.
  4. asin

    The SQLite asin() function returns the arc sine of the specified number.
  5. asinh

    The SQLite asinh() function returns the inverse hyperbolic sine of the specified number.
  6. atan

    The SQLite atan() function returns the arctangent of the specified number.
  7. atan2

    The SQLite atan2() function returns the arc tangent of the result of dividing the specified two numbers, in radians.
  8. atanh

    The SQLite atanh() function returns the inverse hyperbolic tangent of the specified number.
  9. ceil

    The SQLite ceil() function returns the smallest integer value greater than or equal to the number specified by the parameter.
  10. ceiling

    The SQLite ceiling() function returns the smallest integer value greater than or equal to the number specified by the parameter.
  11. cos

    The SQLite cos() function returns the cosine of the specified radian.
  12. cosh

    The SQLite cosh() function returns the hyperbolic cosine of the specified number.
  13. degrees

    The SQLite degrees() function converts the specified radian value to a degree value and returns the result.
  14. floor

    The SQLite floor() function returns the largest integer value less than or equal to the number specified by the parameter.
  15. ln

    The SQLite ln() function returns the natural logarithm of the number specified by the parameter.
  16. log

    The SQLite log() function returns the logarithm of the base (10 default) specified by the parameter.parameter.
  17. log10

    The SQLite log10() function returns the base 10 logarithm for the number specified by the parameter.
  18. log2

    The SQLite log2() function returns the base 2 logarithm for the number specified by the parameter.
  19. max(x,y,...)

    The SQLite max(x,y,...) function returns the largest value in the parameter list.
  20. min(x,y,...)

    The SQLite min(x,y,...) function returns the smallest value in the parameter list.
  21. mod

    The SQLite mod() function returns the remainder after dividing the specified two numbers.
  22. pi

    The SQLite pi() function returns an approximation of π.
  23. pow

    The SQLite pow() function returns a specified number raised to the specified power.
  24. power

    The SQLite power() function returns a specified number raised to the specified power.
  25. radians

    The SQLite radians() unction converts the specified value in degrees to radians and returns the result.
  26. random

    The SQLite random() function returns a pseudorandom integer between -9223372036854775808 and +9223372036854775807.
  27. round

    Learn SQLite round(X, Y) with tested SQL examples for decimal places, negative precision, NULL, halfway values, and numeric versus formatted text.
  28. sign

    The SQLite sign() function returns the sign of the specified number, and returns 1, -1, or 0 respectively if the parameter is positive, negative, or zero.
  29. sin

    The SQLite sin() function returns the sine of the specified radian.
  30. sinh

    The SQLite sinh() function returns the hyperbolic sine of the specified number.
  31. sqrt

    The SQLite sqrt() function returns the square root of a given number.
  32. tan

    The SQLite tan() function returns the tangent of the specified radian.
  33. tanh

    The SQLite tanh() function returns the hyperbolic tangent of the specified number.
  34. trunc

    The SQLite trunc() function returns the integer part of the specified number.