欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php实现数字转换成中文大小写的代码

程序员文章站 2022-05-15 09:46:06
...
  1. //chinese_money.PHP
  2. //Changing Arab Money Num to Chinese Money Num
  3. /*
  4. Functions List:
  5. Chinese_Money_Max()
  6. 小数点前
  7. 此函数可以单独拿出用于将阿拉伯数字转为中文数字(大小写可选,默认为大写)
  8. 仅限整数(正负皆可)
  9. Chinese_Money_Min()
  10. 处理小数点后
  11. Chinese_Money()
  12. by bbs.it-home.org
  13. */
  14. function Chinese_Money_Max($i,$s=1){
  15. $c_digIT_min = array("零","十","百","千","万","亿","兆");
  16. $c_num_min = array("零","一","二","三","四","五","六","七","八","九","十");
  17. $c_digIT_max = array("零","拾","佰","仟","万","亿","兆");
  18. $c_num_max = array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖","拾");
  19. if($s==1){
  20. $c_digIT = $c_digIT_max;
  21. $c_num = $c_num_max;
  22. }else{
  23. $c_digIT = $c_digIT_min;
  24. $c_num = $c_num_min;
  25. }
  26. if($i return "负".Chinese_Money_Max(-$i);
  27. //return "-".Chinese_Money_Max(-$i);
  28. if ($i return $c_num[$i];
  29. if ($i return $c_num[1].$c_digIT[1] . $c_num[$i - 10];
  30. if ($i if ($i % 10)
  31. return $c_num[$i / 10] . $c_digIT[1] . $c_num[$i % 10];
  32. else
  33. return $c_num[$i / 10] . $c_digIT[1];
  34. }
  35. if ($i if ($i % 100 == 0)
  36. return $c_num[$i / 100] . $c_digIT[2];
  37. else if ($i % 100 return $c_num[$i / 100] . $c_digIT[2] . $c_num[0] . Chinese_Money_Max($i % 100);
  38. else if ($i % 100 return $c_num[$i / 100] . $c_digIT[2] . $c_num[1] . Chinese_Money_Max($i % 100);
  39. else
  40. return $c_num[$i / 100] . $c_digIT[2] . Chinese_Money_Max($i % 100);
  41. }
  42. if ($i if ($i % 1000 == 0)
  43. return $c_num[$i / 1000] . $c_digIT[3];
  44. else if ($i % 1000 return $c_num[$i / 1000] . $c_digIT[3] . $c_num[0] . Chinese_Money_Max($i % 1000);
  45. else
  46. return $c_num[$i / 1000] . $c_digIT[3] . Chinese_Money_Max($i % 1000);
  47. }
  48. if ($i if ($i % 10000 == 0)
  49. return Chinese_Money_Max($i / 10000) . $c_digIT[4];
  50. else if ($i % 10000 return Chinese_Money_Max($i / 10000) . $c_digIT[4] . $c_num[0] . Chinese_Money_Max($i % 10000);
  51. else
  52. return Chinese_Money_Max($i / 10000) . $c_digIT[4] . Chinese_Money_Max($i % 10000);
  53. }
  54. if ($i if ($i % 100000000 == 0)
  55. return Chinese_Money_Max($i / 100000000) . $c_digIT[5];
  56. else if ($i % 100000000 return Chinese_Money_Max($i / 100000000) . $c_digIT[5] . $c_num[0] . Chinese_Money_Max($i % 100000000);
  57. else
  58. return Chinese_Money_Max($i / 100000000) . $c_digIT[5] . Chinese_Money_Max($i % 100000000);
  59. }
  60. if ($i % 1000000000000 == 0)
  61. return Chinese_Money_Max($i / 1000000000000) . $c_digIT[6];
  62. else if ($i % 1000000000000 return Chinese_Money_Max($i / 1000000000000) . $c_digIT[6] . $c_num[0] . Chinese_Money_Max($i % 1000000000000);
  63. else
  64. return Chinese_Money_Max($i / 1000000000000) . $c_digIT[6] . Chinese_Money_Max($i % 1000000000000);
  65. }
  66. function Chinese_Money_Min($a){
  67. $c_num = array("零","一","二","三","四","五","六","七","八","九","十");
  68. if($a return $c_num[0] . "角" . $c_num[$a] . "分";
  69. else if($a%10 == 0)
  70. return $c_num[$a/10] . "角" . $c_num[0] . "分";
  71. else
  72. return $c_num[floor($a/10)] . "角" . $c_num[$a%10] ."分";
  73. }
  74. /*小数点后两位*/
  75. function Chinese_Num_Min($a){
  76. $c_num = array("零","一","二","三","四","五","六","七","八","九","十");
  77. if($a return $c_num[0] . $c_num[$a] ;
  78. else if($a%10 == 0)
  79. return $c_num[$a/10] . $c_num[0] ;
  80. else
  81. return $c_num[floor($a/10)] . $c_num[$a%10];
  82. }
  83. function Chinese_Money($i){
  84. $j=Floor($i);
  85. $x=($i-$j)*100;
  86. //return $x;
  87. //return Chinese_Money_Max($j)."元".Chinese_Money_Min($x)."整";
  88. return Chinese_Money_Max($j,'0')."点".Chinese_Num_Min($x);
  89. }
  90. //The Following Code is Testing The Functions:
  91. /*
  92. $e_money =332123.32;
  93. echo Chinese_Money($e_money);
  94. */
  95. ?>
复制代码