PHP 格式化金额小数后面的0
封装格式化金额小数处理去0处理函数
/** * 格式化金额小数后面的0 - 数字金额处理 去掉小数后的0 * @param string $amount 输入 123.123000 * @return string 输出 123.123 */ function number_amount($amount = '0.00'){ $amount = strval($amount); $arr = explode('.',$amount); $amount = $arr[0]; if (count($arr) == 2){ $fNumber = rtrim($arr[1],'0'); if (!empty($fNumber)){ $amount = $amount.'.'.$fNumber; } } if (empty($amount)){ $amount = '0'; } return $amount; }