歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> PHP中處理浮點數的一些方法記錄

PHP中處理浮點數的一些方法記錄

日期:2017/3/1 9:29:33   编辑:Linux編程

請不要在程序中直接使用等號、大於、加、減、乘、除等操作浮點數,如果需要對浮點數進行以上操作,請使用下面的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 幾位小數

Copyright © Linux教程網 All Rights Reserved