1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > php bc 取字符串长度 PHP bcsqrt()用法及代码示例

php bc 取字符串长度 PHP bcsqrt()用法及代码示例

时间:2020-11-12 23:11:42

相关推荐

php bc 取字符串长度 PHP bcsqrt()用法及代码示例

PHP中的bcsqrt()函数是一个内置函数,用于评估任意精度数的平方根。此函数接受任意精度数字作为字符串,并在将结果缩放到指定精度后返回数字的平方根。

用法:

string bcsqrt ( $num_str, $scaleVal)

参数:此函数接受上述语法中所示的三个参数,并在下面进行说明:

$num_str:此参数为字符串类型,表示要求平方根的操作数或数字。此参数是必需的。

$scaleVal:此参数为int类型,是可选的。此参数告诉结果中小数点后出现的位数。默认值为零。

返回值:此函数以字符串形式返回数字$num_str的平方根。

例子:

Input: $num_str = 26

Output: 5

Since the parameter $scaleVal is not specified so

no digits after decimal is appeared in the

result after finding out square root.

Input: $num_str = 26, $scaleVal = 4

Output: 5.0990

以下示例程序旨在说明PHP中的bcsqrt()函数:

程序1:

// PHP program to illustrate bcsqrt() function

// input numbers with arbitrary precision

$num_str = "26";

// calculates the square root when

// $scaleVal is not specified

$res = bcsqrt($num_str);

echo $res;

?>

输出:

5

程序2:

// PHP program to illustrate bcsqrt() function

// input numbers with arbitrary precision

$num_str = "26";

$scale = "4";

// calculates the square root when

// $scaleVal is specified

$res = bcsqrt($num_str, $scale);

echo $res;

?>

输出:

5.0990

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。