您好,欢迎访问一九零五行业门户网

php 把数字1-1亿换成汉字表述,例如 150 转成 一百五十,1-1150_PHP教程

php 把数字1-1亿换成汉字表述,例如 150 转成 一百五十,1-1150直接上实例
写到 千亿上了。
/**
* @author  ja颂 
* 把数字1-1亿换成汉字表述,如:123->一百二十三
* @param [num] $num [数字]
* @return [string] [string]
*/
function numtoword($num)
{
$chinum = array('零', '一', '二', '三', '四', '五', '六', '七', '八', '九');
$chiuni = array('','十', '百', '千', '万', '亿', '十', '百', '千');
$chistr = '';
$num_str = (string)$num;
$count = strlen($num_str);
$last_flag = true; //上一个 是否为0
$zero_flag = true; //是否第一个
$temp_num = null; //临时数字
$chistr = '';//拼接结果
if ($count == 2) {//两位数
$temp_num = $num_str[0];
$chistr = $temp_num == 1 ? $chiuni[1] : $chinum[$temp_num].$chiuni[1];
$temp_num = $num_str[1];
$chistr .= $temp_num == 0 ? '' : $chinum[$temp_num];
}else if($count > 2){
$index = 0;
for ($i=$count-1; $i >= 0 ; $i--) {
$temp_num = $num_str[$i];
if ($temp_num == 0) {
if (!$zero_flag && !$last_flag ) {
$chistr = $chinum[$temp_num]. $chistr;
$last_flag = true;
}
}else{
$chistr = $chinum[$temp_num].$chiuni[$index%9] .$chistr;
$zero_flag = false;
$last_flag = false;
}
$index ++;
}
}else{
$chistr = $chinum[$num_str[0]];
}
return $chistr;
}
$num = 150;
echo numtoword($num);
http://www.bkjia.com/phpjc/1035428.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/1035428.htmltecharticlephp 把数字1-1亿换成汉字表述,例如 150 转成 一百五十,1-1150 直接上实例 写到 千亿上了。 /** * @author ja颂 * 把数字1-1亿换成汉字表述,如:...
其它类似信息

推荐信息