SQLite 3 reference · Math Functions

SQLite TRUNC() Function

Drop the fractional part of a number, rounding toward zero: trunc(2.7) is 2 and trunc(-2.7) is -2.

SQLite 3 Since 3.35.0

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

trunc(X)

Parameters

ParameterDescription
X A number (text that looks like a number is converted).

Return value

The integer part, as a number.

Examples

Toward zero vs floor()
SELECT trunc(2.7) AS a, trunc(-2.7) AS b, floor(-2.7) AS floor_b;

Output

a | b | floor_b
2 | -2 | -3

Run this on your computer — see “Get Started” for setup.

CAST also truncates
SELECT CAST(-2.7 AS INTEGER) AS cast_int;

Output

cast_int
-2

Run this on your computer — see “Get Started” for setup.

This is one of SQLite's built-in math functions, available since 3.35.0 when SQLite is compiled with SQLITE_ENABLE_MATH_FUNCTIONS (the default for the sqlite3 command-line tool and most language bindings). The in-browser SQLite on this site is built without them, so the examples show output from standard SQLite instead.

Version history

VersionChange
SQLite 3.35.0Added

In other languages

Was this page helpful?