|
|
@@ -31,3 +31,28 @@ if (!function_exists('isPhone')) {
|
|
|
return preg_match("/^1[3-9][0-9]]{9}/", $mobile);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 金钱格式化小数点
|
|
|
+ * @param $money
|
|
|
+ * @param int $decimal 小数点位数,默认系统配置2位
|
|
|
+ * @return float
|
|
|
+ */
|
|
|
+function moneyFormat($money, $decimal=null){
|
|
|
+ $formatConfig = [];
|
|
|
+ $charset = !empty($formatConfig['charset'])? trim($formatConfig['charset']) : 'utf-8';
|
|
|
+ if($decimal === null){
|
|
|
+ $decimal = isset($formatConfig['moneyDecimal'])? intval($formatConfig['moneyDecimal']): 2;
|
|
|
+ }
|
|
|
+ $money = round($money, $decimal+1);
|
|
|
+ $data = explode('.', $money);
|
|
|
+ $money = isset($data[0])? $data[0] : 0;
|
|
|
+ $float = isset($data[1])? $data[1] : '';
|
|
|
+ $len = $float? mb_strlen($float, $charset) : 0;
|
|
|
+
|
|
|
+ $decimal = $decimal>=0? intval($decimal) : 2;
|
|
|
+ $num1 = isset($data[1])? $data[1] : '';
|
|
|
+ $float = $len>=$decimal? mb_substr($num1, 0, $decimal, $charset) : $float.str_repeat('0', $decimal-$len);
|
|
|
+ $money = $money.'.'.$float;
|
|
|
+ return number_format($money, $decimal, '.', '');
|
|
|
+}
|