SQLite TRUNC() Function
The SQLite TRUNC() function returns the integer part of a number, rounding toward zero.
Syntax
TRUNC(number)
Parameters
number |
Required. Specify the number to truncate. |
Return Value
Returns the truncated value of the number rounding toward zero.
Example 1:
The example below shows the usage of TRUNC() function.
SELECT TRUNC(1234.5678); Result: 1234.0 SELECT TRUNC(-1234.5678); Result: -1234.0 SELECT TRUNC(1234.56); Result: 1234.0 SELECT TRUNC(-1234.56); Result: -1234.0 SELECT TRUNC(1234); Result: 1234 SELECT TRUNC(-1234); Result: -1234
Example 2:
Consider a database table called Sample with the following records:
Data | x |
---|---|
Data 1 | -3.75567 |
Data 2 | -5.3867 |
Data 3 | 13.9804 |
Data 4 | 93.1601 |
Data 5 | 48.1322 |
The statement given below can be used to truncate the records of column x.
SELECT *, TRUNC(x) AS TRUNC_Value FROM Sample;
This will produce the result as shown below:
Data | x | TRUNC_Value |
---|---|---|
Data 1 | -3.75567 | -3.0 |
Data 2 | -5.3867 | -5.0 |
Data 3 | 13.9804 | 13.0 |
Data 4 | 93.1601 | 93.0 |
Data 5 | 48.1322 | 48.0 |
❮ SQLite Functions