php 精度运算,PHP BC 库(任意精度数字运算) | 网游世界
留意:備選參數$scale以設置運算精度(保留小數位)。
bcscale(設置運算精度)
bool bcscale ( int $scale )
說明:設置運算精度(保留小數位),成功返回TRUE否則為FALSE。
bcadd(加法運算)
string bcadd ( string $left_operand , string $right_operand [, int $scale] )
說明:返回$left_operand+$right_operand的和。
bcsub(減法運算)
string bcsub ( string $left_operand , string $right_operand [, int $scale ] )
返回:$left_operand 減去$right_operand的值。
bcmul(乘法運算)
string bcmul ( string $left_operand , string $right_operand [, int $scale] )
說明:返回$left_operand乘以$right_operand的值。
bcdiv(除法運算)
string bcdiv ( string $left_operand , string $right_operand [, int $scale] )
說明:返回$left_operand除以$right_operand的值。
bccomp(比較運算)
int bccomp ( string $left_operand , string $right_operand [, int $scale] )
說明:返回值為0相等;1,$left_operand大;-1,$right_operand大。
bcmod(取余運算)
string bcmod ( string $left_operand , string $modulus )
說明:返回$left_operand除$modulus的余數。返回 NULL則$modulus為0。
bcpow(次方|冪運算)
string bcpow ( string $left_operand , string $right_operand [, int $scale] )
說明:返回$left_operand的$right_operand次方的冪值。
在不需要精度控制的情況下,將不會返回小數保留位。如<?php
echo bcpow('5', '2', 2); // 顯示 "25", 而不是 "25.00"
?>
bcpowmod(次方取余運算)
string bcpowmod ( string $left_operand , string $right_operand , string $modulus [, int $scale] )
說明:返回$left_operand的$right_operand次方,再與 $modulus取余。
即:($left_operand^$right_operand) mod $modulus<?php
$a = bcpowmod($x, $y, $mod);
$b = bcmod(bcpow($x, $y), $mod);
//$a 和 $b 相同。
?>
bcsqrt(平方根運算)
string bcsqrt ( string $operand [, int $scale] )
說明:返回$operand的平方根。
相關:
總結
以上是生活随笔為你收集整理的php 精度运算,PHP BC 库(任意精度数字运算) | 网游世界的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 抵押车保险怎么理赔
- 下一篇: 动态规划算法php,php算法学习之动态