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.
honor-dd-light-ds-java/doc/move/tool/ZcNumberHelper.php

29 lines
848 B
PHTML

1 year ago
<?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;
}
}