round
Rounds a float
&reftitle.description;
floatround
intfloatnum
intprecision0
intmodePHP_ROUND_HALF_UP
Returns the rounded value of num to
specified precision
(number of digits after the decimal point).
precision can also be negative or zero (default).
&reftitle.parameters;
num
The value to round.
precision
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.
&Constants;
&Description;
PHP_ROUND_HALF_UP
Rounds num away from zero when it is half way there,
making 1.5 into 2 and -1.5 into -2.
PHP_ROUND_HALF_DOWN
Rounds num towards zero when it is half way there,
making 1.5 into 1 and -1.5 into -1.
PHP_ROUND_HALF_EVEN
Rounds num towards the nearest even value when it is half way
there, making both 1.5 and 2.5 into 2.
PHP_ROUND_HALF_ODD
Rounds num towards the nearest odd value when it is half way
there, making 1.5 into 1 and 2.5 into 3.
&reftitle.returnvalues;
The value rounded to the given precision as a &float;.
&reftitle.changelog;
&Version;
&Description;
8.0.0
num no longer accepts internal objects which support
numeric conversion.
&reftitle.examples;
round examples
]]>
&example.outputs;
How precision affects a float
]]>
&example.outputs;
mode examples
]]>
&example.outputs;
mode with precision examples
]]>
&example.outputs;
&reftitle.seealso;
ceil
floor
number_format