You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class ZcNumberHelper {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回当前时间的字符串,以支持BC的系列方法
|
|
|
|
|
*
|
|
|
|
|
* @param integer $dec 精确到小数点后几位
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public static function microtimeFloat($scale = 3) {
|
|
|
|
|
list($usec, $sec) = explode(' ', microtime());
|
|
|
|
|
return bcadd($usec, $sec, $scale);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function numFormat($number, $decimals = 2) {
|
|
|
|
|
return (float)number_format($number, $decimals, '.', '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function percent($divisor, $denominator, $symbol = '%', $decimals = 2){
|
|
|
|
|
if($denominator == 0 && $divisor == 0){
|
|
|
|
|
return '0' . $symbol;
|
|
|
|
|
}
|
|
|
|
|
if($denominator == 0) {
|
|
|
|
|
return '∞' . $symbol;
|
|
|
|
|
}
|
|
|
|
|
return self::numFormat(($divisor / $denominator) * 100, $decimals) . $symbol;
|
|
|
|
|
}
|
|
|
|
|
}
|