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

WBOY
發布: 2023-08-30 14:46:01
轉載
1005 人瀏覽過

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
登入後複製
#

以上是PHP - 如何使用bcsqrt()函數取得任意精確度數字的平方根?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:tutorialspoint.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!