函数名:bcsqrt()
功能:计算任意精度的平方根
适用版本:PHP 4 >= 4.0.4, PHP 5, PHP 7
用法: string bcsqrt ( string $operand [, int $scale = 0 ] )
参数:
- $operand:需要计算平方根的操作数,可以是一个字符串表示的数字。
- $scale(可选):确立结果中小数点后面的位数,默认为0。
返回值: 返回平方根的值作为字符串。
示例:
$number = "15";
$precision = 4;
$result = bcsqrt($number, $precision);
echo "平方根值为:" . $result;
输出:
平方根值为:3.8729
说明:bcsqrt() 函数是使用任意精度数学扩展进行计算的。第一个参数是要计算平方根的数值,它必须是一个字符串类型。第二个参数可选,用于指定结果的小数位数。函数返回一个精确的字符串表示的平方根值。