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, $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 dividend. This parameter is mandatory.
- $num_str2: This parameter is of string type and represents the divisor. 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 division. It’s default value is zero.
Return Value: This function returns the division of the number $num_str1 by $num_str2 as 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
Below programs illustrate the bcdiv() function in PHP :
Program 1:
<?php // PHP program to illustrate bcdiv() function // input numbers $num_str1 = "11.222"; // dividend $num_str2 = "3"; // divisor // calculates the division of // the two numbers when $scaleVal is // not specified $res = bcdiv($num_str1, $num_str2); echo $res; ?> |
Output:
3
Program 2:
<?php // PHP program to illustrate bcdiv() function // input numbers $num_str1 = "11.222"; // dividend $num_str2 = "3"; // divisor // scale value $scaleVal = 4; // calculates the division of the two // numbers when $scaleVal is specified $res = bcdiv($num_str1, $num_str2, $scaleVal); echo $res; ?> |
Output:
3.7406
Reference:
http://php.net/manual/en/function.bcdiv.php
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- How to get the function name inside a function in PHP ?
- PHP | Ds\Map get() Function
- D3.js | d3.min() function
- CSS | rgb() Function
- p5.js | box() Function
- D3.js | d3.map.set() Function
- PHP | exp() Function
- PHP | min( ) Function
- PHP | max( ) Function
- D3.js | d3.rgb() Function
- p5.js | int() function
- D3.js | d3.hcl() Function
- PHP | dir() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



