w3resource

SQLite round() function

Description

SQLite round() function rounds a floating-point value t up to a number of digits to the right of the decimal point. If the 2nd argument (rounded digits) is omitted, it is assumed to be 0.

Syntax:

round(X)
round(X,Y)

SQLite Version: 3.8.5

Argument:

Name Description
X A number which will be rounded upto D decimal places.
Y A number indicating up to how many decimal places N will be rounded.

Note: The arguments can be zero(0) or negative. The default value of ‘Y’ is 0 if not specified. if ‘Y’ is 0, the round will happen from the left of the ‘Y’ decimal point of the value ‘X’.

Example of SQLite round() function

SELECT round(59.9,0);

Here is the result.

Sample Output:

round(59.9,0)
-------------
60.0

The above SQLite statement will round the given number 59.9. No decimal places have been defined, so the default decimal value is 0.

Example: round() function with negative value

SELECT round(-59.9,0);

Here is the result.

Sample Output:

round(-59.9,0)
--------------
-60.0

The above SQLite statement will round the given number -59.9. No decimal places have been defined, so the default decimal value is 0.

Example: round() function using decimal places

SELECT round(-4.535,2);

Here is the result.

Sample Output:

round(-4.535,2)
---------------
-4.54

The above SQLite statement will round the given number -4.535 up to 2 decimal places.

Example: round() function using negative decimal places

SELECT round(34.4158,-1);

Here is the result.

Sample Output:

round(34.4158,-1)
-----------------
34.0

The above SQLite statement will round the given number 34.4158 from the left of decimal place up to 1 place.

Previous: replace()
Next: rtrim()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/sqlite/core-functions-round.php