php的浮点数,php浮点数计算

183e4451dea9

image.png

bcadd — 2个任意精度数字的加法计算

左操作数和右操作数求和 ,scale 用于设置结果中小数点后的小数位数。

bcadd ( string

math?formula=left_operand%20%2C%20stringright_operand [, int $scale ] ) : string

$a = '1.234';

$b = '5';

echo bcadd($a, $b); // 6

echo bcadd($a, $b, 4); // 6.2340

?>

bccomp — 比较两个任意精度的数字

bccomp ( string

math?formula=left_operand%20%2C%20stringright_operand [, int $scale = int ] ) : int

echo bccomp('1.00001', '1', 3); // 0

echo bccomp('1.00001', '1', 5); // 1

?>

bcdiv — 2个任意精度的数字除法计算

bcdiv ( string

math?formula=left_operand%20%2C%20stringright_operand [, int $scale = int ] ) : string

// default scale : 3

bcscale(3);

echo bcdiv('105', '6.55957'); // 16.007

// this is the same without bcscale()

echo bcdiv('105', '6.55957', 3); // 16.007

?>

bcmod — 对一个任意精度数字取模

bcmod ( string

math?formula=left_operand%20%2C%20stringmodulus ) : string

echo bcmod('4', '2'); // 0

echo bcmod('2', '4'); // 2

?>

bcmul — 2个任意精度数字乘法计算

bcmul ( string

math?formula=left_operand%20%2C%20stringright_operand [, int $scale = int ] ) : string

echo bcmul('1.34747474747', '35', 3); // 47.161

echo bcmul('2', '4'); // 8

?>

bcpow — 任意精度数字的乘方

bcpow ( string

math?formula=left_operand%20%2C%20stringright_operand [, int $scale ] ) : string

echo bcpow('4.2', '3', 2); // 74.08

?>

bcpowmod----将任意的精确数提高到另一个,再用指定的模量还原

bcpowmod ( string

math?formula=base%20%2C%20stringexponent , string

math?formula=modulus%20%5B%2C%20intscale = 0 ] ) : string

$a = bcpowmod($x, $y, $mod);

$b = bcmod(bcpow($x, $y), $mod);//

$a and $b are equal to each other.

?>

bcscale 设置全局默认的小数位数

bcscale — 设置所有bc数学函数的默认小数点保留位数

bcscale ( int $scale ) : bool

scale : 3

bcscale(3);

echo bcdiv('105', '6.55957'); // 16.007// this is the same without

bcscale()

echo bcdiv('105', '6.55957', 3); // 16.007

?>

bcsqrt — 任意精度数字的二次方根

bcsqrt ( string

math?formula=operand%20%5B%2C%20intscale ] ) : string

echo bcsqrt('2', 3); // 1.414

?>

bcsub — 2个任意精度数字的减法

bcsub ( string

math?formula=left_operand%20%2C%20stringright_operand [, int $scale = int ] ) : string

$a = '1.234';

$b = '5';

echo bcsub($a, $b); // -3

echo bcsub($a, $b, 4); // -3.7660

?>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值