本文是一个php实现的可以用来把数字转为中文数字的函数方法,感兴趣的同学参考下. <?php function ch_num($num,$mode=true) { $char = array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖"); $dw = array("","拾","佰","仟","","萬","億","兆"); $dec = "點"; $retval = ""; if($mode) preg_match_all(
本文是一个php实现的可以用来把数字转为中文数字的函数方法,感兴趣的同学参考下.
<?php
function ch_num($num,$mode=true) {
$char = array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖");
$dw = array("","拾","佰","仟","","萬","億","兆");
$dec = "點";
$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($ar[1][0] != "") {
$str = strrev($ar[1][0]);
for($i=0;$i<strlen($str);$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");
?>
声明:本文内容来源自网络,文字、图片等素材版权属于原作者,平台转载素材出于传递更多信息,文章内容仅供参考与学习,切勿作为商业目的使用。如果侵害了您的合法权益,请您及时与我们联系,我们会在第一时间进行处理!我们尊重版权,也致力于保护版权,站搜网感谢您的分享!