PHP round( ) Function Last Updated : 22 Jun, 2023 Comments Improve Suggest changes Like Article Like Report While dealing with problems which have values consisting of a very high number of decimal digits such as (121.76763527823) we often come up with a problem of rounding them up. Rounding them up manually can be a very time consuming and erroneous practice. In place of that, an inbuilt function of PHP i.e round() can be used. The round() function in PHP is used to round a floating-point number. It can be used to define a specific precision value which rounds number according to that precision value.Precision can be also negative or zero. The round() function in PHP has 3 parameters which are number, precision, and mode among which the latter two are optional parameters.The round() function returns the rounded value of the argument passed. Syntax: float round($number, $precision, $mode); Parameters: It accepts three parameters out of which one is compulsory and two are optional. All of these parameters are described below: $number: It is the number which you want to round.$precision: It is an optional parameter. It specifies the number of decimal digits to round to. The default value of this parameter is zero.$mode: It is an optional parameter. It specifies a constant to specify the rounding mode. The constant can be one of the following: PHP_ROUND_HALF_UP: This mode tells to round up the number specified by parameter $number by precision specified by parameter $precision away from zero.PHP_ROUND_HALF_DOWN: This mode tells to round up the number specified by parameter $number by precision specified by parameter $precision towards zero.PHP_ROUND_HALF_EVEN: This mode tells to round up the number specified by parameter $number by precision specified by parameter $precision towards nearest even value.PHP_ROUND_HALF_ODD: This mode tells to round up the number specified by parameter $number by precision specified by parameter $precision towards nearest odd value. Return Value: It returns the rounded value. Examples: Input : round(0.70) Output : 1 Input : round(0.708782) Output : 0.71 Input : round(-3.40) Output : -3 Input : round(-3.60) Output : -4 Below programs illustrate the working of round() in PHP: When a parameter is passed with default precision i.e. '0': PHP <?php echo(round(0.70)); ?> Output: 1When a parameter is passed with a specific precision value: PHP <?php echo(round(0.70878, 2)); ?> Output: 0.71When a negative value is passed as a parameter: PHP <?php echo(round(-3.40)); ?> Output: -3Passing parameters with mode: PHP <?php // round to nearest even value echo(round(7.5,0,PHP_ROUND_HALF_EVEN)); echo "\n"; // round to nearest odd value echo(round(7.5,0,PHP_ROUND_HALF_ODD)); echo "\n"; // round towards zero echo(round(7.5,0,PHP_ROUND_HALF_DOWN)); echo "\n"; // round away from zero echo(round(7.5,0,PHP_ROUND_HALF_UP)); ?> Output: 8 7 7 8 Important Points To Note: round() function is used to round floating-point numbers.A specific precision value can be used to get the desired results.Precision value can also be negative or zero. Reference: http://php.net/manual/en/function.round.php Comment More infoAdvertise with us Next Article PHP round( ) Function S Shubrodeep Banerjee Follow Improve Article Tags : Misc Web Technologies PHP PHP-math PHP-function +1 More Practice Tags : Misc Similar Reads PHP rand() Function In this article, we will see how to get the random number using the rand() function in PHP, along with knowing its implementation through the example. The rand() is an inbuilt function in PHP used to generate a random number ie., it can generate a random integer value in the range [min, max]. Syntax 2 min read PHP range() Function The range() function is an inbuilt function in PHP which is used to create an array of elements of any kind such as integer, alphabets within a given range(from low to high) i.e, list's first element is considered as low and last one is considered as high. Syntax: array range(low, high, step) Parame 3 min read PHP pos() Function The pos() is an inbuilt function in PHP which is used to return the value of the element in an array which the internal pointer is currently pointing to. The pos() function does not increment or decrement the internal pointer after returning the value. In PHP all arrays have an internal pointer. Thi 2 min read PHP strlen() Function The strlen() is a built-in function in PHP which returns the length of a given string.It calculates the length of the string including all the whitespaces and special characters. Syntax:strlen($string);Parameters: This parameter represents the string whose length is needed to be returned. Return Val 1 min read PHP urlencode() Function The urlencode() function is an inbuilt PHP function used to encode the URL. This function returns a string consisting of all non-alphanumeric characters exceptâ_. It is replaced by the percent (%) sign, followed by two hex digits and spaces encoded as plus (+) signs. Syntax:string urlencode( $input 1 min read PHP trim() Function The trim() function in PHP is an inbuilt function which removes whitespaces and also the predefined characters from both sides of a string that is left and right. Related Functions: PHP | ltrim() Function PHP | rtrim() Function Syntax: trim($string, $charlist) Parameters:The function accepts one man 2 min read PHP String Functions Strings are a fundamental data type in PHP, used to store and manipulate text. PHP provides a wide variety of built-in string functions. These functions perform various operations such as string transformations, character manipulations, encoding and decoding, and formatting, making string handling s 6 min read PHP | print_r() Function The print_r() function is a built-in function in PHP and is used to print or display information stored in a variable. Syntax: print_r( $variable, $isStore ) Parameters: This function accepts two parameters as shown in above syntax and described below. $variable: This parameter specifies the variabl 2 min read PHP | random_int() Function The random_int () is an inbuilt function in PHP. The main function is to generate cryptographically secure pseudo-random integers value. When unbiased results occur in critical condition, then generated cryptographic random integers are used.The different sources of randomness used in this function 2 min read PHP array_rand() Function This inbuilt function of PHP is used to fetch a random number of elements from an array. The element is a key and can return one or more than one key. On a practical basis, this is not that useful because the function uses pseudo-random number generator that is not suitable for cryptographic purpose 2 min read Like