Home > Common Problem > What does round function mean?

What does round function mean?

小老鼠
Release: 2024-04-24 13:51:13
Original
542 people have browsed it

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?

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>
Copy after login

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.
  1. 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.
  2. 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!

Related labels:
git
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template