PHP function to convert RMB amount figures into Chinese capital letters

WBOY
Release: 2016-07-25 09:04:24
Original
1173 people have browsed it
  1. /**
  2. Convert the RMB amount to Chinese capital letters
  3. link: bbs.it-home.org
  4. date: 2013-2-28
  5. */
  6. function cny($ns) {
  7. static $cnums=array("zero","壹","谰","三","四","五","鲁","撒","八","九"),
  8. $cnyunits=array("circle","angle","fen"),
  9. $grees =array("十","百","千","万","十","百","千","万");
  10. list($ns1,$ns2)=explode(". ",$ns,2);
  11. $ns2=array_filter(array($ns2[1],$ns2[0]));
  12. $ret=array_merge($ns2,array(implode("",_cny_map_unit(str_split( $ns1),$grees)),""));
  13. $ret=implode("",array_reverse(_cny_map_unit($ret,$cnyunits))));
  14. return str_replace(array_keys($cnums),$cnums,$ ret);
  15. }
  16. function _cny_map_unit($list,$units) {

  17. $ul=count($units);
  18. $xs=array();
  19. foreach (array_reverse($list ) as $x) {
  20. $l=count($xs);
  21. if ($x!="0" || !($l%4)) $n=($x=='0'?'' :$x).($units[($l-1)%$ul]);
  22. else $n=is_numeric($xs[0][0])?$x:'';
  23. array_unshift($xs, $n);
  24. }
  25. return $xs;
  26. }
  27. ?>
Copy code

Usage: Pass numeric parameters directly PHP function to convert RMB amount figures into Chinese capital letters The following example prints out uppercase numbers and outputs the result: one thousand two thousand one hundred twenty one yuan

  1. echo cny('12121');
  2. ?>
Copy code


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!