Home > Backend Development > PHP Tutorial > A function to convert Arabic numerals to Chinese numerals, Arabic Chinese_PHP tutorial

A function to convert Arabic numerals to Chinese numerals, Arabic Chinese_PHP tutorial

WBOY
Release: 2016-07-13 10:23:41
Original
1269 people have browsed it

A function that converts Arabic numerals to Chinese numerals, Arabic Chinese

最近因需要,写了个“阿拉伯数字转中文数字的函数”。搜索了精华区只见到一个类似的。
感觉到我的算法不错,所以贴出来共享一下如果要用于金额的转换,对小数部分的处理要做一下修改
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 $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");
?>

​ ​ ​

Detailed instructions: http://php.662p.com/thread-364-1-1.html

How to convert Arabic numerals into Chinese capital letters in Excel 2010 number? (No function required, is there any tool for direct conversion)

Right-click the cell and select "Format Cells",
In the "Number" tab, select "Special" on the left and "Chinese Uppercase Numbers" on the right

How to convert Chinese numbers to Arabic numerals in excel? ?

There is no direct method in this regard. It depends on what kind of rules your data has to decide which function to use to help. Please give an example and be more detailed. If it doesn't work, please send the file for analysis.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/834764.htmlTechArticleA function to convert Arabic numerals to Chinese numerals. Arabic Chinese recently wrote a function to convert Arabic numerals to Chinese numerals due to need. function. I searched the highlights section and found only one similar one. Feeling...
Related labels:
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