In PHP, the bcsqrt() function is used to get the square root of an arbitrary precision number. It accepts an arbitrary precision number as a string and gives the square root of that number after scaling the result to the specified precision.
string bcsqrt($num_string, $scale)
bcsqrt()The function accepts two different parameters: $num_string and $scale. p>
$num_string - It represents the number whose square root is to be calculated. String type parameter.
$scale − represents the number of digits appearing after the decimal point in the output. p>
bcsqrt()The function returns the square root of the number in string form.
< h2>Example 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
The above is the detailed content of PHP - How to get the square root of an arbitrary precision number using the bcsqrt() function?. For more information, please follow other related articles on the PHP Chinese website!