Php code for converting numbers into Chinese characters in case

Source: Internet
Author: User
Php code for converting numbers into Chinese characters in case

  1. // Chinese_money.PHP
  2. // Changing Arab Money Num to Chinese Money Num
  3. /*
  4. Functions List:
  5. Chinese_Money_Max ()
  6. Before Decimal point
  7. This function can be used to convert an Arabic number into a Chinese number separately (case-sensitive). The default value is uppercase)
  8. Only integers (positive and negative)
  9. Chinese_Money_Min ()
  10. After Decimal point processing
  11. Chinese_Money ()
  12. By bbs.it-home.org
  13. */
  14. Function Chinese_Money_Max ($ I, $ s = 1 ){
  15. $ C_digIT_min = array ("0", "10", "", "MB ");
  16. $ C_num_min = array ("zero", "one", "two", "three", "four", "five", "six", "seven ", "8", "9", "10 ");
  17. $ C_digIT_max = array ("0", "pick up", "success", "success", "", "megabytes ");
  18. $ C_num_max = array ("zero", "one", "two", "three", "si", "Wu", "Lu", "Lu ", "Pick", "pick ");
  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/100000000). $ 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 % 1000000000000 <100000000)
  76. Return Chinese_Money_Max ($ I/1000000000000). $ c_digIT [6]. $ c_num [0]. Chinese_Money_Max ($ I % 1000000000000 );
  77. Else
  78. Return Chinese_Money_Max ($ I/1000000000000). $ c_digIT [6]. Chinese_Money_Max ($ I % 1000000000000 );
  79. }
  80. Function Chinese_Money_Min ($ ){
  81. $ C_num = array ("zero", "one", "two", "three", "four", "five", "six", "seven ", "8", "9", "10 ");
  82. If ($ a <10)
  83. Return $ c_num [0]. "". $ c_num [$ a]. "points ";
  84. Else if ($ a % 10 = 0)
  85. Return $ c_num [$ a/10]. "". $ c_num [0]. "points ";
  86. Else
  87. Return $ c_num [floor ($ a/10)]. "". $ c_num [$ a % 10]. "points ";
  88. }
  89. /* Two digits after the decimal point */
  90. Function Chinese_Num_Min ($ ){
  91. $ C_num = array ("zero", "one", "two", "three", "four", "five", "six", "seven ", "8", "9", "10 ");
  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). "yuan". 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. ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.