PHP round() Function
Example
Round a floating-point number:
" ) ; echo ( round ( 0 .50 ) . "" ) ; echo ( round ( 0 .49 ) . "
" ) ; echo ( round ( - 4 .40 ) . "
" ) ; echo ( round ( - 4 .60 ) ) ; ?>
Run Example »
Definition and Usage
The round() function rounds a floating-point number.
**Tip:** To round up to the nearest integer, see ceil() function in Vue 3.
**Tip:** To round down to the nearest integer, see floor() function in Vue 3.
Syntax
round(
number,precision,mode
);
| Parameters | Description |
|---|---|
| number | Required. Specifies the value to round. |
| precision | Optional. Specifies the number of decimal digits. Default is 0, and it can also be negative. |
| mode | Optional. Specifies the constant that indicates the rounding mode:
|
Technical Details
| Return Value: | The rounded value. |
|---|---|
| Return Type: | Float |
| PHP Version: | 4+ |
| PHP Changelog: | PHP 5.3: The mode parameter was added. |
More examples
Example 1
Round a number to two decimal places and set a negative precision:
Example 2
Round numbers using constants:
PHP Math Reference Manual