ROUND function rounds a number to a specified number of digits. Usage: ROUND(number, num_digits), where number is the target number, num_digits is the number of rounding digits, positive values are rounded to the right, and negative values are rounded to the left. Steps: 1. Divide by 10 to the power of num_digits; 2. Round according to the rules; 3. Multiply by 10 to the power of num_digits.
![What does round function mean?](https://img.php.cn/upload/article/202404/24/2024042413511561399.jpg)
Meaning of ROUND function
The ROUND function is used to round a number to a specified number of digits.
Syntax
<code>ROUND(number, num_digits)</code>
Parameters
##number: The number to be rounded. - num_digits: Number of digits to round to. Negative values round to the left, positive values round to the right.
-
Working principle
ROUND function works through the following steps:
Divide number by 10 raised to the num_digits power to get an intermediate result. - If the decimal part of the intermediate result is greater than or equal to 0.5 (for right rounding) or less than 0.5 (for left rounding), then the intermediate result is rounded to the nearest integer.
- Multiply the rounded integer by 10 raised to the num_digits power to get the final result.
-
Example
ROUND(123.45, 0) returns 123 (rounded to the left to an integer)- ROUND(123.45, 1) Returns 123.5 (rounded to the right to one decimal place)
- ROUND(123.45, -1) Returns 120 (rounded to the left to the tenth place)
-
The above is the detailed content of What does round function mean?. For more information, please follow other related articles on the PHP Chinese website!
Statement: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