Home > Backend Development > PHP Tutorial > Implement a function to convert Arabic numerals to Chinese numerals under PHP_PHP Tutorial

Implement a function to convert Arabic numerals to Chinese numerals under PHP_PHP Tutorial

WBOY
Release: 2016-07-21 15:51:03
Original
985 people have browsed it

If you want to use it for the conversion of amounts, you need to modify the processing of the decimal part

function ch_num($num,$mode=true) {
$char = array( "zero", "one", "two", "three", "four", "five", "Lu", "旒", "eight", "玖");
$dw = array(" ","十","百","千","","万","Billion"," trillion");
$dec = "point";
$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, process the decimals recursively first
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");

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319217.htmlTechArticleIf you want to use it for the conversion of amounts, you need to modify the processing of the decimal part?php functionch_num($num, $mode=true){ $char=array("zero","one","two","three","four","五","鲁","七","八","九." ..
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template