PHP | bccomp() Function Last Updated : 19 Apr, 2018 Comments Improve Suggest changes Like Article Like Report The bccomp() function in PHP is an inbuilt function and is used to compare two arbitrary precision numbers. This function accepts two arbitrary precision numbers as strings and returns the result of comparison of the two numbers after comparing them upto a specified precision. Syntax: int bccomp ( $num_str1, $num_str2, $scaleVal) Parameters: This function accepts three parameters as shown in the above syntax and explained below. $num_str1: This parameter is of string type and represents the left operand or one of the two numbers among which we want to perform the comparison. This parameter is mandatory. $num_str2: This parameter is of string type and represents the right operand or one of the two numbers among which we want to perform the comparison. This parameter is mandatory. $scaleVal: This parameter is of int type and is optional. This parameter tells the number of digits after decimal places that will be used in comparison. The default value of this parameter is zero. Return Value: This function returns an integral value based on the comparison of the two numbers $num_str1 and $num_str2. If both of the numbers are equal then this function returns zero. If $num_str1 is greater than $num_str2 this function returns 1 and if $num_str1 is less than $num_str2 this function returns -1. Examples: Input: $num_str1 = 3.22, $num_str2 = 3 Output: 0 Explanation: Since the parameter $scaleVal is not specified so no digits after decimal is used in comparison. So, the value of first parameter which is 3.22 will be treated as 3 and hence both parameters are equal. Input: $num_str1 = 3.222, $num_str2 = 3, $scaleVal = 2 Output: 1 Input: $num_str1 = 3, $num_str2 = 3.222, $scaleVal = 2 Output: -1 Below programs illustrate the bccomp() function in PHP : Program 1: php <?php // PHP program to illustrate bccomp() function // input numbers $num_str1 = "3.12"; $num_str2 = "3"; // calculates the comparison of the two // numbers when $scaleVal is not specified $res = bccomp($num_str1, $num_str2, 2); // both parameters are equal echo $res; ?> Output: 0 Program 2: php <?php // PHP program to illustrate bccomp() function // input numbers $num_str1 = "3.12"; $num_str2 = "3"; // scale value $scaleVal = 2; // calculates the comparison of the two // numbers when $scaleVal is specified $res = bccomp($num_str1, $num_str2, $scaleVal); // first parameter is greater than second echo $res; ?> Output: 1 Program 3: php <?php // PHP program to illustrate bccomp() function // input numbers $num_str1 = "3"; $num_str2 = "3.12"; // scale value $scaleVal = 2; // calculates the comparison of the two // numbers when $scaleVal is specified $res = bccomp($num_str1, $num_str2, $scaleVal); // first parameter is smaller than second echo $res; ?> Output: -1 Reference: http://php.net/manual/en/function.bccomp.php Comment More infoAdvertise with us Next Article PHP | bccomp() Function B barykrg Follow Improve Article Tags : Web Technologies PHP PHP-bc Similar Reads PHP compact() Function The compact() function is an inbuilt function in PHP and it is used to create an array using variables. This function is the opposite of the extract() function. It creates an associative array whose keys are variable names and their corresponding values are array values. Syntax: array compact("varia 2 min read PHP | bcpow() Function The bcpow() function in PHP is an inbuilt function and is used to calculate the value of an arbitrary precision base number raised to another exponent number. This function accepts two arbitrary precision numbers as strings and returns the base number raised to exponent after scaling the result to a 2 min read PHP | bcmul() Function The bcmul() function in PHP is an inbuilt function and is used to multiply two arbitrary precision numbers. This function accepts two arbitrary precision numbers as strings and returns the multiplication of the two numbers after scaling the result to a specified precision. Syntax: string bcmul ( $nu 2 min read PHP | bcmod() Function The bcmod() function in PHP is an inbuilt function and is used to calculate modulus of an arbitrary precision numbers. This function accepts an arbitrary precision number and returns the modulus of that number after scaling the result to a specified precision. Syntax: string bcadd ( $dividend, $modu 2 min read PHP cos( ) Function Trigonometry is an important part of mathematics and PHPâs math functions provides us with some functions which are very useful for calculations involving trigonometry. The cos()function in PHP is used to find the cosine of a number. The cos() function returns a float value between -1 and 1, which r 2 min read PHP | bcpowmod() Function The bcpowmod() function in PHP is an inbuilt function and is used to raise an arbitrary precision base number to another exponent number reduced by a specified modulus. This function accepts three arbitrary precision numbers as strings and returns the base number raised to exponent modulo under a nu 2 min read PHP acos( ) Function Trigonometry is an important part of mathematics and PHPâs math functions provides us with some functions which are very useful for calculations involving trigonometry. One of such function is acos() function. The acos() function in PHP is used to find the arc cosine of a number in radians. We alrea 2 min read PHP | bcscale() Function The bcscale() function is an inbuilt function in PHP. It sets the default scale parameters for all bc math function calls. When we call the function bcscale() in a program, the parameter passed in this function thus becomes the default scale factor which by default is zero. Syntax: int bcscale($scal 2 min read PHP | gmp_com() Function The gmp_com() is an inbuilt function in PHP which is used to calculate the one's complement of a GMP number(GNU Multiple Precision : For large numbers). Syntax: gmp_com($num) Parameters: This function accepts a GMP number $num as a mandatory parameter as shown in the above syntax. This parameter can 2 min read PHP | gmp_cmp() Function The gmp_cmp() is an inbuilt function in PHP which is used to compare two GMP numbers(GNU Multiple Precision : For large numbers). Syntax: gmp_cmp($num1, $num2) Parameters: This function accepts two GMP numbers $num1 and $num2 as mandatory parameters as shown in the above syntax for comparing. These 2 min read Like