Home  >  Article  >  Backend Development  >  PHP code to convert numbers into Chinese upper and lower case

PHP code to convert numbers into Chinese upper and lower case

WBOY
WBOYOriginal
2016-07-25 08:56:00840browse
  1. //chinese_money.PHP
  2. //Changing Arab Money Num to Chinese Money Num
  3. /*
  4. Functions List:
  5. Chinese_Money_Max()
  6. Before the decimal point
  7. This function can be used separately Convert Arabic numerals to Chinese numerals (uppercase and lowercase are optional, default is uppercase)
  8. Only integers (both positive and negative)
  9. Chinese_Money_Min()
  10. Process after decimal point
  11. Chinese_Money()
  12. by bbs.it-home.org
  13. */
  14. function Chinese_Money_Max($i,$s=1){
  15. $c_digIT_min = array("zero","ten","hundred","thousand","ten thousand","billion","trillion" );
  16. $c_num_min = array("zero","one","two","three","four","five","six","seven","eight","nine","ten ");
  17. $c_digIT_max = array("zero","hundred","hundred","qian","ten thousand","billion","trillion");
  18. $c_num_max = array("zero"," "一","二","三","四","五","鲁","撒","八","九","十");
  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<0)
  27. return "negative". Chinese_Money_Max(-$i);
  28. //return "-".Chinese_Money_Max(-$i);
  29. if ($i < 11)
  30. return $c_num[$i];
  31. if ($i < 20)
  32. return $c_num[1].$c_digIT[1] . $c_num[$i - 10];
  33. if ($i < 100) {
  34. if ($i % 10)
  35. return $c_num[$i / 10] . $c_digIT[1] . $c_num[$i % 10];
  36. else
  37. return $c_num[$i / 10] . $c_digIT[1];
  38. }
  39. if ($i < 1000) {
  40. if ( $i % 100 == 0)
  41. return $c_num[$i / 100] . $c_digIT[2];
  42. else if ($i % 100 < 10)
  43. return $c_num[$i / 100] . $c_digIT [2] . $c_num[0] . Chinese_Money_Max($i % 100);
  44. else if ($i % 100 < 10)
  45. return $c_num[$i / 100] . $c_digIT[2] . $c_num[ 1] . Chinese_Money_Max($i % 100);
  46. else
  47. return $c_num[$i / 100] . $c_digIT[2] . Chinese_Money_Max($i % 100);
  48. }
  49. if ($i < 10000) {
  50. if ($i % 1000 == 0)
  51. return $c_num[$i / 1000] . $c_digIT[3];
  52. else if ($i % 1000 < 100)
  53. return $c_num[$i / 1000] . $c_digIT[3] . $c_num[0] . Chinese_Money_Max($i % 1000);
  54. else
  55. return $c_num[$i / 1000] . $c_digIT[3] . Chinese_Money_Max($i % 1000);
  56. }
  57. if ($i < 100000000) {
  58. if ($i % 10000 == 0)
  59. return Chinese_Money_Max($i / 10000) . $c_digIT[4];
  60. else if ($i % 10000 < 1000)
  61. return Chinese_Money_Max($i / 10000) . $c_digIT[4] . $c_num[0] . Chinese_Money_Max($i % 10000);
  62. else
  63. return Chinese_Money_Max($i / 10000) . $c_digIT[4] . Chinese_Money_Max($ i % 10000);
  64. }
  65. if ($i < 1000000000000) {
  66. if ($i % 100000000 == 0)
  67. return Chinese_Money_Max($i / 100000000) . $c_digIT[5];
  68. else if ($i % 100000000 < 1000000)
  69. return Chinese_Money_Max($i / 100000000) . $c_digIT[5] . $c_num[0] . Chinese_Money_Max($i % 100000000);
  70. else
  71. return Chinese_Money_Max($i / 10000 0000) .$c_digIT [5] . Chinese_Money_Max($i % 100000000);
  72. }
  73. if ($i % 1000000000000 == 0)
  74. return Chinese_Money_Max($i / 1000000000000) . $c_digIT[6];
  75. else if ($i % 100 0000000000< ; 100000000)
  76. return Chinese_Money_Max($i / 1000000000000) . $c_digIT[6] . $c_num[0] . Chinese_Money_Max($i % 1000000000000);
  77. else
  78. return_Money_Max($i / Chinese 100000000 0000) . $c_digIT[6] . Chinese_Money_Max($i % 1000000000000);
  79. }
  80. function Chinese_Money_Min($a){
  81. $c_num = array("zero","one","two","three","four","five", "six","seven","eight","nine","ten");
  82. if($a<10)
  83. return $c_num[0] . "angle" . $c_num[$a] . "points ";
  84. else if($a%10 == 0)
  85. return $c_num[$a/10] . "angle" . $c_num[0] . "point";
  86. else
  87. return $c_num[floor($a /10)] . "angle" . $c_num[$a%10] ."cent";
  88. }
  89. /*Two decimal places*/
  90. function Chinese_Num_Min($a){
  91. $c_num = array("zero","one","two","three","four","five","six" ,"seven","eight","nine","ten");
  92. if($a<10)
  93. return $c_num[0] . $c_num[$a] ;
  94. else if($a%10 = = 0)
  95. return $c_num[$a/10] . $c_num[0] ;
  96. else
  97. return $c_num[floor($a/10)] . $c_num[$a%10];
  98. }
  99. function Chinese_Money($i){
  100. $j=Floor($i);
  101. $x=($i-$j)*100;
  102. //return $x;
  103. //return Chinese_Money_Max($j)." ".Chinese_Money_Min($x)."whole";
  104. return Chinese_Money_Max($j,'0')."point".Chinese_Num_Min($x);
  105. }
  106. //The Following Code is Testing The Functions:
  107. / *
  108. $e_money =332123.32;
  109. echo Chinese_Money($e_money);
  110. */
  111. ?>
Copy code


Statement:
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