PHP bcmul()函数使用方法
admin
2022-06-09 08:57:05
bcmul()函数是什么?
bcmul()函数是将二个任意精度的数字相乘,传入二个字符串,以左边的数字字符串 (left operand) 乘以右边的 (right operand) 数字字符串。结果亦以字符串返回。scale 是一个可有可无的选项,表示返回值的小数点后所需的位数。
bcmul()函数语法:
- bcmul ( string $left_operand , string $right_operand [, int $scale = 0 ] ) : string
left_operand:字符串类型的左操作数.
right_operand:字符串类型的右操作数.
scale:此可选参数用于设置结果中小数点后的小数位数。也可通过使用 bcscale() 来设置全局默认的小数位数,用于所有函数。
参数:此函数接受上述语法中显示的三个参数,并解释如下:
- string bcmul ( $num_str1, $num_str2, $scaleVal)
$num_str1:此参数为字符串类型,表示要执行乘法的左操作数或两个数字之一。此参数是必需的。
$num_str2:此参数为字符串类型,表示要执行乘法运算的右操作数或两个数字之一。此参数是必需的。
$scaleval:此参数为int类型,可选。此参数指示乘法结果中小数点后将出现的位数。它的默认值是零。
返回值:此函数以字符串形式返回两个数字$num_str1和$num_str2的乘法。
bcmul()函数返回值: 字符串
- string bcmul(string left operand, string right operand, int [scale]);
bcmul()函数函数种类: 数学运算
下面的程序演示了PHP中的bcmul()函数:
程序1:
Output:33
- <?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;
- ?>
程序2:
Output:33.666
- <?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;
- ?>
bcmul()函数实例:
Output: 33
- Input: $num_str1 = 3, $num_str2 = 11.222
说明:因为参数$scaleval不是指定,因此不显示小数点后的数字在乘法后的结果中。
Output: 36.6660
- Input: $num_str1 = 3, $num_str2 = 11.222, $scaleVal = 4
¥ 打赏
×
如果您觉得文章帮助了您就打赏一下吧
非常感谢你的打赏,我们将继续分享更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏
本文《PHP bcmul()函数使用方法》发布于石头博客文章,作者:admin,如若转载,请注明出处:https://www.pweb123.com/html/php/861.html,否则禁止转载,谢谢配合!
文章点评