设为首页 加入收藏

TOP

PHP中处理浮点数的一些方法记录
2015-07-16 12:56:51 来源: 作者: 【 】 浏览:3
Tags:PHP 处理 点数 一些 方法 记录

请不要在程序中直接使用等号、大于、加、减、乘、除等操作浮点数,如果需要对浮点数进行以上操作,请使用下面的BC系列函数。以确保准确性及精度。


两个高精度数比较大小


int bccomp ( string $left_operand , string $right_operand [, int $scale ] )


left=right 返回 0


left

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 几位小数


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Go 语言的分布式读写互斥 下一篇C#的未来:闭包注解

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: