PHP Bcdiv () Function

PHP

Syntax:
string bcdiv ($num_str1, $num_str2, $scaleVal)
Parameters:This function takes three parameters, as shown in the above syntax and explained below:
  • $num_str1 : This parameter is of string type and represents a dividend. This parameter is required.
  • $num_str2 : This parameter is of type string and represents the divisor. This parameter is required.
  • $scaleVal : This parameter is int and is optional. This parameter reports the number of digits that will appear after the decimal fraction as a result of division. The default is zero.
Returned value:This function returns the division of $num_str1 by $num_str2 in as a string.Examples:
Input: $num_str1 = 11.222, $num_str2 = 3 Output: 3 Since the parameter $scaleVal is not specified so no digits after decimal is appeared in the result after division. Input: $num_str1 = 11.222, $num_str2 = 3, $scaleVal = 4 Output: 3.7406
The following programs illustrate the bcdiv() function in PHP:Program 1: < / strong>
// PHP program to illustrate the bcdiv function() 
// enter numbers $num_str1 = "11.222" ; // dividend $num_str2 = "3" ; // divider 
// calculates the division
// two numbers when $scaleVal is
// not specified $res = bcdiv ( $num_str1 , $num_str2 ); echo $res ;  
?>
Output:
3
Program 2:
// PHP program to illustrate the bcdiv() function 
// enter numbers $num_str1 = "11.222" ; // dividend $num_str2 = "3" ; // divider 
// scaleVal $scaleVal = 4;  
// calculates the division of two
// numbers when $scaleVal is specified $res = bcdiv ( $num_str1 , $num_str2 , $scaleVal ); echo $res ;  
?>
Output:
3.7406
Link:
http://php.net/manual/ en / function.bcdiv.php



Get Solution for free from DataCamp guru