在 PHP 中,bcsqrt() 函数用于获取任意精度数字的平方根。它接受任意精度数字作为字符串,并在将结果缩放到指定精度后给出该数字的平方根。
string bcsqrt($num_string, $scale)
bcsqrt()函数接受两个不同的参数:$num_string和$scale。 p>
$num_string - 它表示要计算其平方根的数字。字符串类型参数。
$scale − 表示输出中小数点后出现的位数。 p>
bcsqrt()函数以字符串形式返回数字的平方根。
示例1<?php // input numbers with arbitrary precision $num_string = "22"; // below bcsqrt function calculates the square root $result= bcsqrt($num_string); echo "Output without scale value: ", $result; ?>
Output without scale value: 4
<?php // input numbers with arbitrary precision $num_string = "22"; //scale value 3 $scale="3"; // below bcsqrt function calculates the square root $result= bcsqrt($num_string, $scale); echo "Output with scale value: ", $result; ?>
Output with scale value: 4.690
以上就是PHP - 如何使用bcsqrt()函数获取任意精度数字的平方根?的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号