PHP: round() function
Description
The round() function is used to round a floating-point number.
Version:
(PHP 4 and above)
Syntax:
round (num1, num2, mode)
Parameters:
Name | Description | Required / Optional |
Type |
---|---|---|---|
num1 | The numeric expression whose value is to be rounded. | Required | Float |
num2 | The number of decimal digits to round to. | Optional | Integer |
mode | Rounding mode. Possible values : PHP_ROUND_HALF_UP, PHP_ROUND_HALF_DOWN, PHP_ROUND_HALF_EVEN, PHP_ROUND_HALF_ODD. |
Optional | Integer |
Return value
The rounded value.
Value Type : Float.
Pictorial Presentation
Example:
Output :
Round of (13,4) is : 13 Round of (13,5) is : 14 Round of (13,6) is : 14 Round of (13.6,0) is : 14 Round of (5.85543,2) is : 5.86 Round of (5.85543,-3) is : 0 Round of (6.054,2) is : 6.05 Round of (6.066,2) is : 6.07
View the example in the browser
See also