"零","壹","贰","叁","肆","伍","陆","柒","捌","玖");//var $advan">
当前位置:Gxlcms > PHP教程 > 只支持整数的小写金额转中文大写的函数

只支持整数的小写金额转中文大写的函数

时间:2021-07-01 10:21:17 帮助过:30人阅读

  1. /*

  2. 只支持整数的小写金额转中文大写
  3. */
  4. class ChineseNumber
  5. {
  6. //var $basical=array(0=>"零","一","二","三","四","五","六","七","八","九");
  7. var $basical=array(0=>"零","壹","贰","叁","肆","伍","陆","柒","捌","玖");
  8. //var $advanced=array(1=>"十","百","千");
  9. var $advanced=array(1=>"拾","佰","仟");
  10. var $top=array(1=>"万","亿");

  11. var $level; // 以4位为一级

  12. // 先实现万一下的数的转换

  13. function small2big($number)
  14. {
  15. if ($number>999999999999) // 只能处理到千亿。
  16. return "数字太大,无法处理。抱歉!";
  17. if ($number==0)
  18. return "零";

  19. for($this->level=0;$number>0.0001;$this->level++,$number=floor($number / 10000))

  20. {
  21. // 对于中文来说,应该是4位为一组。
  22. // 四个变量分别对应 个、十、百、千 位。
  23. $n1=substr($number,-1,1);
  24. if($number>9)
  25. $n2=substr($number,-2,1);
  26. else
  27. $n2=0;
  28. if($number>99)
  29. $n3=substr($number,-3,1);
  30. else
  31. $n3=0;
  32. if($number>999)
  33. $n4=substr($number,-4,1);
  34. else
  35. $n4=0;

  36. if($n4)

  37. $parsed[$this->level].=$this->basical[$n4].$this->advanced[3];
  38. else
  39. if(($number/10000)>=1) // 千位为0,数值大于9999的情况
  40. $parsed[$this->level].="零";
  41. if($n3)
  42. $parsed[$this->level].=$this->basical[$n3].$this->advanced[2];
  43. else
  44. if(!ereg("零$",$parsed[$this->level]) && ($number / 1000)>=1) //不出现连续两个“零”的情况
  45. $parsed[$this->level].="零";
  46. if($n2)
  47. $parsed[$this->level].=$this->basical[$n2].$this->advanced[1];
  48. else
  49. if(!ereg("零$",$parsed[$this->level]) && ($number / 100)>=1) //不出现连续两个“零”的情况
  50. $parsed[$this->level].="零";
  51. if($n1)
  52. $parsed[$this->level].=$this->basical[$n1];
  53. }
  54. for($this->level-=1;$this->level>=0;$this->level--)
  55. {
  56. $result.=$parsed[$this->level].$this->top[$this->level];
  57. }

  58. if(ereg("零$",$result))

  59. $result=substr($result,0,strlen($result)-2);

  60. return $result;

  61. }
  62. };

  63. $big=new ChineseNumber();

  64. echo $big->small2big(1311);
  65. ?>

人气教程排行