PHP | bcmod()函数

PHP中的bcmod()函数是一个内置函数,用于计算任意精度数字的模。此函数接受任意精度的数字,并在将结果缩放到指定精度后返回该数字的模。

null

语法:

string bcadd ( $dividend, $modulus)

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

  • 美元红利 :此参数为字符串类型,表示将除以给定模值$module的股息。此参数是必需的。
  • 美元模数 :此参数为字符串类型,表示模数。此参数是必需的。

返回值: 此函数在以下情况下返回余数: 美元红利 除以 美元模数 换句话说,它返回的值相当于($Distribution%$Modules)。如果$module为零,则此函数返回NULL。

例如:

Input:  $dividend = 11, $modulus = 3
Output: 2

Input:  $dividend = 3, $modulus = 11
Output: 3

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

项目1:

<?php
// PHP program to illustrate bcmod() function
// input numbers with arbitrary precision
$dividend = "11" ;
$modulus = "3" ;
// calculates the modulus
$res = bcmod ( $dividend , $modulus );
echo $res ;
?>


输出:

2

项目2:

<?php
// PHP program to illustrate bcmod() function
// input numbers with arbitrary precision
$dividend = "3" ;
$modulus = "11" ;
// calculates the modulus
$res = bcmod ( $dividend , $modulus );
echo $res ;
?>


输出:

3

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

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