PHP中的bcpow()函数是一个内置函数,用于计算提升到另一个指数的任意精度基数的值。此函数接受两个任意精度的数字作为字符串,并在将结果缩放到指定精度后返回提升为指数的基数。
null
语法:
string bcpow ( $base, $exponent, $scaleVal )
参数: 此函数接受三个参数,如上面的语法所示,如下所述:
- $base :此参数为字符串类型,表示将提升功率的基准。此参数是必需的。
- $exponent :此参数为字符串类型,表示指数。此参数是必需的。
- $scaleVal :此参数为int类型,是可选的。此参数表示基数结果中小数点后出现的位数 拥护者 .它的默认值为零。
返回值: 此函数返回$base $exponent 结果为字符串。
例如:
Input: $base = 2, $exponent = 3 Output: 8 Since the parameter $scaleVal is not specified so no digits after decimal is appeared in the result after evaluating result Input: $base = 2, $exponent = 3, $scaleVal = 2 Output: 8 Note: Instead of 8.00, output of 8 is given. This is an exception in bc math functions.
下面的程序演示了PHP中的bcpow()函数:
项目1:
<?php // PHP program to illustrate bcpow() function // input numbers with arbitrary precision $base = "2" ; $exponent = "3" ; // calculates the base^exponent // the two numbers when $scaleVal is // not specified $res = bcpow( $base , $exponent ); echo $res ; ?> |
输出:
2
项目2:
<?php // PHP program to illustrate bcpow() function // input numbers with arbitrary precision $base = "2" ; $exponent = "3" ; // scale value $scaleVal = 4; // calculates the base^exponent // the two numbers when $scaleVal is // specified $res = bcpow( $base , $exponent , $scaleVal ); echo $res ; ?> |
输出:
2
参考: http://php.net/manual/en/function.bcpow.php
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END