Recently, because of the need, wrote a "Arabic numerals to Chinese numbers function." The search for the essence area saw a similar one.
I feel my algorithm is good, so paste it out to share if you want to use for the amount of conversion, the number of parts of the processing to do a change
function Ch_num ($num, $mode =true) {
$char = Array ("0", "one", "II", "three", "the", "WU", "Lu", "Qi", "ba", "JIU");
$DW = Array ("", "Pick", "Bai", "Thousand", "" "," Million "," Yi "," Mega ");
$dec = "dot";
$retval = "";
if ($mode)
Preg_match_all ("/^0* (\d*) \.?" (\d*)/", $num, $ar);
Else
Preg_match_all ("/(\d*) \.? (\d*)/", $num, $ar);
if ($ar [2][0]! = "")
$retval = $dec. Ch_num ($ar [2][0],false); If there are decimals, the decimal is first processed recursively
if ($ar [1][0]! = "") {
$str = Strrev ($ar [1][0]);
for ($i =0; $i
$out [$i] = $char [$STR [$i]];
if ($mode) {
$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)];
}
}
$retval = Join ("", Array_reverse ($out)). $retval;
}
return $retval;
}
Echo ch_num ("12345006789001.123");
Echo ch_num ("880079.1234");
Echo ch_num ("300045.0123");
?>
http://www.bkjia.com/PHPjc/314475.html www.bkjia.com true http://www.bkjia.com/PHPjc/314475.html techarticle recently, because of the need, wrote a "Arabic numerals to Chinese numbers function." The search for the essence area saw a similar one. Feel my algorithm is good, so paste it out to share a bit if ...