Home  >  Article  >  Backend Development  >  php小写金额转大写

php小写金额转大写

WBOY
WBOYOriginal
2016-06-23 13:49:071065browse

public static function num_case($num) {

$return = "";
$unit = array("分", "角", "元", "整");
$dw = array("", "拾", "佰", "仟", "", "万", "亿", "兆");
$char = array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖");
preg_match_all("/(\d*)\.?(\d*)/", $num, $ar);

if($ar[2][0] != ""){
$return .= $ar[2][0][0] == 0 ? "" : $char[$ar[2][0][0]] . $unit[1];
if(isset($ar[2][0][1])) $return .= $char[$ar[2][0][1]] . $unit[0];
}else{
$return .= $unit[3];
}


if ($ar[1][0] != "") {
$str = strrev($ar[1][0]);
$len = strlen($str);
$return = $unit[2] . $return;
for ($i = 0; $i $out[$i] = $char[$str[$i]];
$out[$i] .= $str[$i] != "0"? $dw[$i%4] : "";
if ($str[$i] + $str[$i-1] == 0)
$out[$i] = "";
if ($i%4 == 0)
$out[$i] .= $dw[4+floor($i/4)];
}
$return = join("",array_reverse($out)) . $return;
}
return $return;


}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn