首页 / 操作系统 / Linux / PHP中处理浮点数的一些方法记录
请不要在程序中直接使用等号、大于、加、减、乘、除等操作浮点数,如果需要对浮点数进行以上操作,请使用下面的BC系列函数。以确保准确性及精度。两个高精度数比较大小int bccomp ( string $left_operand , string $right_operand [, int $scale ] )left=right 返回 0left<right 返回 -1left>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 几位小数本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-05/117171.htm