PHP Velho Oeste 2024

bcsqrt

(PHP 4, PHP 5, PHP 7)

bcsqrtGet the square root of an arbitrary precision number

Descrierea

bcsqrt ( string $num , int|null $scale = null ) : string

Return the square root of the num.

Parametri

num

The operand, as a string.

scale

Acest parametru opțional este utilizat pentru a stabili numărul cifrelor după virgulă din rezultat. Dacă este omis, valoarea implicită va fi cea stabilită global cu funcția bcscale(), sau va fi 0 dacă nu a fost stabilită cu ajutorul acestei funcții.

Valorile întoarse

Returns the square root as a string, or null if num is negative.

Istoricul schimbărilor

Versiune Descriere
8.0.0 scale is now nullable.

Exemple

Example #1 bcsqrt() example

<?php

echo bcsqrt('2'3); // 1.414

?>

A se vedea și

  • bcpow() - Raise an arbitrary precision number to another

add a note add a note

User Contributed Notes 1 note

up
1
markogrady18 at gmail dot com
9 years ago
The bcsqrt function is very handy for finding the square root of numbers in the form of strings.

//EXAMPLE:
   
<?php

$arr
= array(
       
"one" => "20",
        
"two" => "12"
   
);

echo
bcsqrt($arr["one"], 3);

//OUTPUT: 4.472
To Top