Home > Database > Oracle > How to use round function in oracle

How to use round function in oracle

下次还敢
Release: 2024-05-07 15:48:18
Original
546 people have browsed it

The ROUND function in Oracle can round numbers to a specified precision. The syntax is: ROUND(number, decimals). Among them, number is the number to be rounded, and decimals is the rounding precision. Example: Round 123.456 to one decimal place: ROUND(123.456, 1); Round to two decimal places: ROUND(123.456, 2); Round to an integer: ROUND(123.456, 0).

How to use round function in oracle

ROUND Function in Oracle

The ROUND function is used to round a number to a specified precision. It has the following syntax:

<code>ROUND(number, decimals)</code>
Copy after login

where:

  • number is the number to be rounded.
  • decimals is the precision to be rounded to.

Usage Examples

The following are some usage examples of the ROUND function:

  • Round 123.456 to one decimal place :
<code>SELECT ROUND(123.456, 1) FROM dual;</code>
Copy after login

Output:

<code>123.5</code>
Copy after login
  • Round 123.456 to two decimal places:
<code>SELECT ROUND(123.456, 2) FROM dual;</code>
Copy after login

Output:

<code>123.46</code>
Copy after login
  • Round 123.456 to an integer:
<code>SELECT ROUND(123.456, 0) FROM dual;</code>
Copy after login

Output:

<code>123</code>
Copy after login

Notes

  • Ifdecimals is a positive number, the function rounds the number to the specified number of decimal places after the decimal point.
  • If decimals is negative, the function rounds the number to the specified number of decimal places before the decimal point.
  • If decimals is 0, the function rounds the number to the nearest integer.
  • If number is NULL, the function returns NULL.

The above is the detailed content of How to use round function in oracle. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template