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