PHP round() Function
The round() function rounds a floating-point number.
float round ( float $val [, int $precision = 0 [, int $mode = PHP_ROUND_HALF_UP ]] )
Returns the rounded value of val to specified precision (number of digits after the decimal point). precision can also be negative or zero (default).
Example -
Example -
Example -
Parameter | Description
|
number | Required. Specifies the value to round
|
precision | Optional. Specifies the number of decimal digits to round to. Default is 0
|
mode | Optional. Specifies a constant to specify the rounding mode:
|
| PHP_ROUND_HALF_UP - Default. Rounds number up to precision decimal, when it is half way there. Rounds 1.5 to 2 and -1.5 to -2
|
| PHP_ROUND_HALF_DOWN - Round number down to precision decimal places, when it is half way there. Rounds 1.5 to 1 and -1.5 to -1
|
| PHP_ROUND_HALF_EVEN - Round number to precision decimal places towards the next even value
|
| PHP_ROUND_HALF_ODD - Round number to precision decimal places towards the next odd value
|
Return Values
The rounded value