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的平方根。

相关:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值