卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章64334本站已运行4115

PHP - 如何使用bcsqrt()函数获取任意精度数字的平方根?

PHP - 如何使用bcsqrt()函数获取任意精度数字的平方根?

在 PHP 中,bcsqrt() 函数用于获取任意精度数字的平方根。它接受任意精度数字作为字符串,并在将结果缩放到指定精度后给出该数字的平方根。

语法

string bcsqrt($num_string, $scale)

参数

bcsqrt()函数接受两个不同的参数:$num_string$scale

  • $num_string - 它表示要计算其平方根的数字。字符串类型参数。

  • $scale − 表示输出中小数点后出现的位数。

返回值

bcsqrt()函数以字符串形式返回数字的平方根。

< h2>示例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

示例 2

<?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

卓越飞翔博客
上一篇: C++程序创建盒子并计算体积,并使用小于运算符进行检查
下一篇: 在C语言中,近指针、远指针和巨型指针
留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏