(PHP 4, PHP 5, PHP 7, PHP 8)
round — Rounds a float
$num, int $precision = 0, int|RoundingMode $mode = RoundingMode::HalfAwayFromZero): float
Returns the rounded value of num to
specified precision
(number of digits after the decimal point).
precision can also be negative or zero (default).
numThe value to round.
precisionThe optional number of decimal digits to round to.
If the precision is positive, num is
rounded to precision significant digits after the decimal point.
If the precision is negative, num is
rounded to precision significant digits before the decimal point,
i.e. to the nearest multiple of pow(10, -$precision), e.g. for a
precision of -1 num is rounded to tens,
for a precision of -2 to hundreds, etc.
modeUse RoundingMode or one of the following constants to specify the mode in which rounding occurs.
| Constants | Description |
|---|---|