[共享源码]数字转换成中文大写

Meteorlet 2005-06-02 09:58:30
$CHDIGIT= array('零','壹','贰','叁','肆','伍','陆','柒','捌','玖');
$CHUNIT1 = array('','万','亿');
$CHUNIT2 = array('','拾','佰','千');
function ChineseSpellNumber($number)
{
$strNumber = '';
global $CHDIGIT, $CHUNIT1;

$j = 0;
while( !empty($number) )
{
$thousands = substr($number, -4);
$tmp = trim(GetThousands((int)$thousands));
if ($j<sizeof($CHUNIT1))
{
$chunit = $CHUNIT1[$j];
} else {
$chunit = '';
for ($k = 0; $k <= $j - sizeof($CHUNIT1); $k++)
{
$chunit .= $CHUNIT1[1];
}
$chunit .= $CHUNIT1[2];
}
$chunit = "<font color='#0000FF'>$chunit</font>";
$strNumber = $tmp.(empty($tmp)? '' : $chunit).$strNumber;
$number = substr($number, 0, -4);
$j ++;
}
$strNumber = trim($strNumber, $CHDIGIT[0]);
return $strNumber;
}

function GetThousands($thousands)
{
global $CHDIGIT, $CHUNIT2;
$n = (int)$thousands;
$j = 0;
while ($n > 0)
{
$mod = $n % 10;
$n = floor($n /10);
$tmp = $CHDIGIT[$mod]. ($mod==0?'':$CHUNIT2[$j]);
$result = $tmp . $result;
$j ++;
}
if (strlen($thousands) < 4) $result = $CHDIGIT[0].$result;
$result = preg_replace('/('.$CHDIGIT[0].')+/', '$1', $result);
$result = preg_replace('/('.$CHDIGIT[0].')+$/', '', $result);

return $result;
}
测试地址:http://www.dictworld.com/search.php?q=1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890&lang=cn
...全文
125 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
ImN1 2005-06-04
  • 打赏
  • 举报
回复
英文特有趣
Meteorlet 2005-06-03
  • 打赏
  • 举报
回复
本来数字超过8位以上就没什么用,我之所以限制长度在50位以内,仅仅是为了测试而已,还不至于打击我的自信。
jaexc 2005-06-03
  • 打赏
  • 举报
回复
呵呵
不错的哈
支持
zairwolf 2005-06-03
  • 打赏
  • 举报
回复
我是逗笑,毋怪。
Meteorlet 2005-06-03
  • 打赏
  • 举报
回复
共享源码,有什么问题就提,列个结果什么意思?
flyonet 2005-06-03
  • 打赏
  • 举报
回复
唠叨就是老道。

呵呵,一测试就要打击别人的自信了。
xuzuning 2005-06-03
  • 打赏
  • 举报
回复
1,234,567,890,123,456,789,012,345,678,901,234,567,890


Num.
1. 壹千贰佰叁拾肆万万万万万万万亿伍千陆佰柒拾捌万万万万万万亿玖千零壹拾贰万万万万万亿叁千肆佰伍拾陆万万万万亿柒千捌佰玖拾万万万亿壹千贰佰叁拾肆万万亿伍千陆佰柒拾捌万亿玖千零壹拾贰亿叁千肆佰伍拾陆万柒千捌佰玖拾

2. One Two Hundred Thirty Four Five Hundred Sixty Seven Eight Hundred Ninety One Hundred Twenty Three Four Hundred Fifty Six Seven Hundred Eighty Nine Twelve Three Hundred Forty Five Six Hundred Seventy Eight Trillion, Nine Hundred One Billion, Two Hundred Thirty Four Million, Five Hundred Sixty Seven Thousand, Eight Hundred Ninety

zairwolf 2005-06-03
  • 打赏
  • 举报
回复
100,000,000,000,000,000


Num.
1. 壹拾万万亿

2. One Hundred

zairwolf 2005-06-03
  • 打赏
  • 举报
回复
111,111,111,111,111,111,111,111,111,111


Num.
1. 壹拾壹万万万万万亿壹千壹佰壹拾壹万万万万亿壹千壹佰壹拾壹万万万亿壹千壹佰壹拾壹万万亿壹千壹佰壹拾壹万亿壹千壹佰壹拾壹亿壹千壹佰壹拾壹万壹千壹佰壹拾壹

2. One Hundred Eleven One Hundred Eleven One Hundred Eleven One Hundred Eleven One Hundred Eleven One Hundred Eleven Trillion, One Hundred Eleven Billion, One Hundred Eleven Million, One Hundred Eleven Thousand, One Hundred Eleven

zairwolf 2005-06-03
  • 打赏
  • 举报
回复
晕。

21,893

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧