admin 发表于 2014-12-29 17:13:00

PHP如何将阿拉伯数字转换成中文数字

PHP如何将阿拉伯数字转换成中文数字

以下函数 仅供参考:ToChinaseNum.php源码:<?php
/*
*阿拉伯数字转换成中文数字
*/
header('Content-Type: text/html; charset=utf-8');
function ToChinaseNum($num){
$char = array("零","一","二","三","四","五","六","七","八","九");
$dw = array("","十","百","千","万","亿","兆");
$retval = "";
$proZero = false;
for($i = 0;$i < strlen($num);$i++){
if($i > 0){
$temp = (int)(($num % pow (10,$i+1)) / pow (10,$i));
}else{
$temp = (int)($num % pow (10,1));
}
if($proZero == true && $temp == 0) continue;
if($temp == 0) $proZero = true;
else $proZero = false;
if($proZero){
if($retval == "") continue;
$retval = $char[$temp].$retval;
}else $retval = $char[$temp].$dw[$i].$retval;
}
if($retval == "一十") $retval = "十";
return $retval;
}
echo ToChinaseNum(1).'<br />';
echo ToChinaseNum(10).'<br />';
echo ToChinaseNum(55).'<br />';
echo ToChinaseNum(100).'<br />';
echo ToChinaseNum(1001).'<br />';
echo ToChinaseNum(10000).'<br />';

函数未考虑输出为0 以及小数等写法。自行参考修改即可。
页: [1]
查看完整版本: PHP如何将阿拉伯数字转换成中文数字