加入收藏 | 设为首页 | 会员中心 | 我要投稿 应用网_丽江站长网 (http://www.0888zz.com/)- 科技、建站、数据工具、云上网络、机器学习!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP中处理浮点数的一些技巧记录

发布时间:2021-12-10 20:43:49 所属栏目:PHP教程 来源:互联网
导读:请不要在程序中直接使用等号、大于、加、减、乘、除等操作浮点数,如果需要对浮点数进行以上操作,请使用下面的BC系列函数。以确保准确性及精度。 两个高精度数比较大小 int bccomp ( string $left_operand , string $right_operand [, int $scale ] ) left=r
请不要在程序中直接使用等号、大于、加、减、乘、除等操作浮点数,如果需要对浮点数进行以上操作,请使用下面的BC系列函数。以确保准确性及精度。
 
两个高精度数比较大小
 
int bccomp ( string $left_operand , string $right_operand [, int $scale ] )
 
left=right 返回 0
 
left<right 返回 -1
 
left>right 返回 1
 
$scale 需要比较的精度,即小数点后多少位
 
两个高精度数相加
 
string bcadd ( string $left_operand , string $right_operand [, int $scale ] )
 
$scale 相加后,返回几位小数
 
两个高精度数相减
 
string bcsub ( string $left_operand , string $right_operand [, int $scale ] )
 
$scale 相减后,返回几位小数
 
两个高精度数求余/取模
 
string bcmod ( string $left_operand , string $modulus )
 
两个高精度数相除
 
string bcdiv ( string $left_operand , string $right_operand [, int $scale ] )
 
$scale 相除后,返回几位小数
 
两个高精度数相乘
 
string bcmul ( string $left_operand , string $right_operand [, int $scale ] )
 
$scale 相乘后,返回几位小数
 
两个高精度数的次方值
 
string bcpow ( string $left_operand , string $right_operand [, int $scale ] )
 
$scale 次方,返回几位小数
 
高精度数的平方根
 
string bcsqrt ( string $operand [, int $scale ] )
 
$scale 返回几位小数
 
设置bc函数的小数点位数
 
bool bcscale ( int $scale )
 
$scale 几位小数

(编辑:应用网_丽江站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读