首页 > Web开发 > 详细

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

时间:2015-04-29 10:07:51      阅读:236      评论:0      收藏:0      [点我收藏+]

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

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

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

原文:http://blog.csdn.net/hel12he/article/details/45342387

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!