ホームページ  >  記事  >  バックエンド開発  >  PHP - bcsqrt() 関数を使用して任意精度の数値の平方根を取得するには?

PHP - bcsqrt() 関数を使用して任意精度の数値の平方根を取得するには?

WBOY
WBOY転載
2023-08-30 14:45:02973ブラウズ

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

PHP では、bcsqrt() 関数を使用して、任意精度の数値の平方根を取得します。任意の精度の数値を文字列として受け入れ、結果を指定された精度にスケーリングした後、その数値の平方根を返します。

構文

string bcsqrt($num_string, $scale)

パラメータ

bcsqrt()この関数は、2 つの異なるパラメータを受け入れます: $num_string $規模###。 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

例 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 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事はtutorialspoint.comで複製されています。侵害がある場合は、admin@php.cn までご連絡ください。