你好,游客 登录 注册 搜索
背景:
阅读新闻

PHP中处理浮点数的一些方法记录

[日期:2015-05-07] 来源:Linux社区  作者:hel12he [字体:大 中 小]

请不要在程序中直接使用等号、大于、加、减、乘、除等操作浮点数,如果需要对浮点数进行以上操作,请使用下面的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 几位小数

本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-05/117171.htm

linux
相关资讯       PHP处理浮点数  PHP浮点数 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款