PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular

round

Tags: PHP 5.x PHP 7.x PHP 8.x

round — Rounds a float.

Description

round(
    int|float $num, 
    int $precision = 0, 
    int $mode = PHP_ROUND_HALF_UP
): 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).

Parameters

num
The value to round.
characters
The 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.
mode
Use one of the following constants to specify the mode in which rounding occurs.

Return Values

The value rounded to the given precision as a float.