Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
PHP round() Function
Definition and Usage
The round() function proves useful in rounding any floating point number upto a desired precision level. Positive precision parameter causes the number to be rounded after decimal point, whereas with negative precision, rounding occurs before decimal point. Precision is 0 by default.
For example, round(10.6) returns 11, round(10.2) returns 10. The function always returns a floating point number.
This function also has another optional parameter called mode takes one of the redefined constants described later.
Syntax
round ( float $value , int $precision , int $mode ) : float
Parameters
| Sr.No | Parameter & Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 1 |
value A float number to be rounded |
|||||||||
| 2 |
precision number of decimal digits to round to. Default is 0. Positive precision rounds given number after decimal point. Negative precision rounds the given number before decimal point. |
|||||||||
| 3 |
mode one of the following predefined constants
|
Return Values
PHP round() function returns a float number thatby rounding the value todesired precision.
PHP Version
This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.
Example
<?php echo "round( 3.45,HALF_ODD) = " . round(3.45,0, PHP_ROUND_HALF_ODD) . "
"; echo "round(3.78 HALF_EVEN) = " . round(3.78, 0, PHP_ROUND_HALF_EVEN) . "
"; ?>
Output
This will produce following result −
round( 3.45,HALF_ODD) = 3 round(3.78, HALF_EVEN) = 4
