PHP | bcdiv()函数

PHP中的bcdiv()函数是一个内置函数,用于分割两个任意精度的数字。此函数接受两个任意精度的数字作为字符串,并在将结果缩放到指定精度后返回两个数字的除法。

null

语法:

string bcdiv ( $num_str1, $num_str2, $scaleVal)

参数: 此函数接受三个参数,如上面的语法所示,如下所述:

  • $num_str1 :此参数为字符串类型,表示股息。此参数是必需的。
  • $num_str2 :此参数为字符串类型,表示除数。此参数是必需的。
  • $scaleVal :此参数为int类型,是可选的。此参数表示除法结果中小数点后出现的位数。它的默认值是零。

返回值: 此函数返回数字的除法 $num_str1 通过 $num_str2 就像绳子一样。

例如:

Input:  $num_str1 = 11.222, $num_str2 = 3
Output: 3
Since the parameter $scaleVal is not specified so
no digits after decimal is appeared in the 
result after division.

Input:  $num_str1 = 11.222, $num_str2 = 3, $scaleVal = 4
Output: 3.7406

下面的程序演示了PHP中的bcdiv()函数:

项目1:

<?php
// PHP program to illustrate bcdiv() function
// input numbers
$num_str1 = "11.222" ; // dividend
$num_str2 = "3" ; // divisor
// calculates the division of
// the two numbers when $scaleVal is
// not specified
$res = bcdiv ( $num_str1 , $num_str2 );
echo $res ;
?>


输出:

3

项目2:

<?php
// PHP program to illustrate bcdiv() function
// input numbers
$num_str1 = "11.222" ; // dividend
$num_str2 = "3" ; // divisor
// scale value
$scaleVal = 4;
// calculates the division of the two
// numbers when $scaleVal is specified
$res = bcdiv ( $num_str1 , $num_str2 , $scaleVal );
echo $res ;
?>


输出:

3.7406

参考: http://php.net/manual/en/function.bcdiv.php

© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享