PHP | bcadd() Function Last Updated : 19 Apr, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The bcadd() function in PHP is an inbuilt function and is used to add two arbitrary precision numbers. This function accepts two arbitrary precision numbers as strings and returns the addition of the two numbers after scaling the result to a specified precision. Syntax: string bcadd ( $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 addition. 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 addition. This parameter is mandatory. $scaleVal: This parameter is of int type and is optional. This parameter tells the number of digits that will appear after the decimal in the result of addition. It's default value is zero. Return Value: This function returns the addition of the two numbers $num_str1 and $num_str2 as string. Examples: Input: $num_str1 = 3, $num_str2 = 11.222 Output: 14 Since the parameter $scaleVal is not specified so no digits after decimal is appeared in the result after addition. Input: $num_str1 = 3, $num_str2 = 11.222, $scaleVal = 4 Output: 14.2220 Below programs illustrate the bcadd() function in PHP : Program 1: php <?php // PHP program to illustrate bcadd() function // input numbers with arbitrary precision $num_str1 = "3"; $num_str2 = "11.222"; // calculates the addition of // the two numbers when $scaleVal is // not specified $res = bcadd($num_str1, $num_str2); echo $res; ?> Output: 14 Program 2: php <?php // PHP program to illustrate bcadd() function // input numbers with arbitrary precision $num_str1 = "3"; $num_str2 = "11.222"; // scale value $scaleVal = 4; // calculates the addition of the two // numbers when $scaleVal is specified $res = bcadd($num_str1, $num_str2, $scaleVal); echo $res; ?> Output: 14.2220 Reference: http://php.net/manual/en/function.bcadd.php Comment More infoAdvertise with us Next Article PHP | bcmod() Function B barykrg Follow Improve Article Tags : Web Technologies PHP PHP-bc Similar Reads 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 | bcdiv() Function The bcdiv() function in PHP is an inbuilt function and is used to divide two arbitrary precision numbers. This function accepts two arbitrary precision numbers as strings and returns the division of the two numbers after scaling the result to a specified precision. Syntax: string bcdiv ( $num_str1, 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 | 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 | 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 Like