PHP中的bcsub()函数是一个内置函数,用于从一个任意精度的数字中减去另一个。此函数接受两个任意精度的数字作为字符串,并在将结果缩放到指定精度后返回两个数字的减法。
null
语法:
string bcsub ( $num_str1, $num_str2, $scaleVal)
参数: 此函数接受三个参数,如上面的语法所示,如下所述:
- $num_str1 :此参数为字符串类型,表示左操作数或要执行减法的两个数字之一。此参数是必需的。
- $num_str2 :此参数为字符串类型,表示要执行减法的右操作数或两个数字之一。此参数是必需的。
- $scaleVal :此参数为int类型,是可选的。此参数表示加法结果中小数点后出现的位数。它的默认值是零。
返回值: 此函数返回两个数字的减法运算 $num_str1 和 $num_str2 就像绳子一样。
例如:
Input: $num_str1 = 11.222, $num_str2 = 3 Output: 14 Since the parameter $scaleVal is not specified so no digits after decimal is appeared in the result after subtraction. Input: $num_str1 = 11.222, $num_str2 = 3, $scaleVal = 4 Output: 8.2220
下面的程序演示了PHP中的bcsub()函数:
项目1:
<?php // PHP program to illustrate bcsub() function // input numbers with arbitrary precision $num_str1 = "11.222" ; $num_str2 = "3" ; // calculates the subtraction of // the two numbers when $scaleVal is // not specified $res = bcsub( $num_str1 , $num_str2 ); echo $res ; ?> |
输出:
8
项目2:
<?php // PHP program to illustrate bcsub() function // input numbers with arbitrary precision $num_str1 = "11.222" ; $num_str2 = "3" ; // scale value $scaleVal = 4; // calculates the subtraction of the two // numbers when $scaleVal is specified $res = bcsub( $num_str1 , $num_str2 , $scaleVal ); echo $res ; ?> |
输出:
8.2220
参考: http://php.net/manual/en/function.bcsub.php
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END