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 ( $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 multiplication. 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 multiplication. 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 multiplication. It’s default value is zero.
Return Value: This function returns the multiplication of the two numbers $num_str1 and $num_str2 as string.
Examples:
Input: $num_str1 = 3, $num_str2 = 11.222 Output: 33 Explanation: Since the parameter $scaleVal is not specified so no digits after decimal is appeared in the result after multiplication. Input: $num_str1 = 3, $num_str2 = 11.222, $scaleVal = 4 Output: 36.6660
Below programs illustrate the bcmul() function in PHP :
Program 1:
<?php // PHP program to illustrate bcmul() function // input numbers with arbitrary precision $num_str1 = "3"; $num_str2 = "11.222"; // calculates the multiplication of the two // numbers when $scaleVal is not specified $res = bcmul($num_str1, $num_str2); echo $res; ?> |
Output:
33
Program 2:
<?php // PHP program to illustrate bcmul() function // input numbers with arbitrary precision $num_str1 = "3"; $num_str2 = "11.222"; // scale value $scaleVal = 3; // calculates the multiplication of the two // numbers when $scaleVal is specified $res = bcmul($num_str1, $num_str2, $scaleVal); echo $res; ?> |
Output:
33.666
Reference:
http://php.net/manual/en/function.bcmul.php
<!–
–>

How to get the function name inside a function in PHP ?

PHP 5 vs PHP 7

PHP | Get PHP configuration information using phpinfo()

PHP | php.ini File Configuration

How to import config.php file in a PHP script ?

How to include content of a PHP file into another PHP file ?

PHP | imagecreatetruecolor() Function

PHP fpassthru( ) Function

PHP | ImagickDraw getTextAlignment() Function

PHP | Ds\Sequence last() Function




Please Login to comment…