PHP round() function
Definition and Usage
The round() function rounds floating-point numbers.
Syntax
round(x,prec)
Parameter | Description |
---|---|
x | Optional. Specifies the number to be rounded. |
prec | Optional. Specifies the number of decimal places after the decimal point. |
Description
Returns x According to the specified precision prec The rounding result of the number of decimal places after the decimal point (decimal).prec It can also be a negative number or zero (default).
Tips and Notes
Note:PHP cannot handle strings like "12,300.2" correctly by default.
Note:prec The parameter was introduced in PHP 4...
Example
<?php echo(round(0.60)); echo(round(0.50)); echo(round(0.49)); echo(round(-4.40)); echo(round(-4.60)); ?>
Output:
1 1 0 -4 -5