Arabic numerals into Chinese characters (large, lowercase)

Source: Internet
Author: User
To turn numbers into Chinese characters
Wrote one of his own
  1. function Number2chinese ($num, $m = 1) {
  2. Switch ($m) {
  3. Case 0:
  4. $CNum = Array (
  5. Array (' 0 ', ' one ', ' II ', ' three ', ' establishments ', ' Wu ', ' Lu ', ' qi ', ' ba ', ' JIU '),
  6. Array (', ' Pick ', ' bai ', ' thousand '),
  7. Array (', ' million ', ' Yi ', ' billions ')
  8. );
  9. Break
  10. Default
  11. $CNum = Array (
  12. Array (' 0 ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six ', ' seven ', ' eight ', ' nine '),
  13. Array (' ', ' ten ', ' hundred ', ' thousand '),
  14. Array (', ' million ', ' billion ', ' trillion ')
  15. );
  16. Break
  17. }
  18. $cNum = Array (' 0 ', ' one ', ' two ', ' three ', ' four ', ' V ', ' VI ', ' VII ', ' VIII ', ' IX ');
  19. if (Is_integer ($num)) {
  20. $int = (string) $num;
  21. } else if (Is_numeric ($num)) {
  22. $num = Explode ('. ', (String) floatval ($num));
  23. $int = $num [0];
  24. $FL = Isset ($num [1])? $num [1]: FALSE;
  25. }
  26. Length
  27. $len = strlen ($int);
  28. Chinese
  29. $chinese = Array ();
  30. Reversed number
  31. $str = Strrev ($int);
  32. for ($i = 0; $i < $len; $i +=4) {
  33. $s = Array (0=> $str [$i], 1=> $str [$i +1], 2=> $str [$i +2], 3=> $str [$i +3]);
  34. $j = ";
  35. Thousands
  36. if ($s [3]!== ") {
  37. $s [3] = (int) $s [3];
  38. if ($s [3]!== 0) {
  39. $j. = $CNum [0][$s [3]]. $CNum [1][3];
  40. } else {
  41. if ($s [2]! = 0 | | $s [1]! = 0 | | $s [0]!=0] {
  42. $j. = $CNum [0][0];
  43. }
  44. }
  45. }
  46. Hundred
  47. if ($s [2]!== ") {
  48. $s [2] = (int) $s [2];
  49. if ($s [2]!== 0) {
  50. $j. = $CNum [0][$s [2]]. $CNum.
  51. } else {
  52. if ($s [3]!=0 && ($s [1]! = 0 | | $s [0]!=0]) {
  53. $j. = $CNum [0][0];
  54. }
  55. }
  56. }
  57. Ten
  58. if ($s [1]!== ") {
  59. $s [1] = (int) $s [1];
  60. if ($s [1]!== 0) {
  61. $j. = $CNum [0][$s [1]]. $CNum [1][1];
  62. } else {
  63. if ($s [0]!=0 && $s [2]! = 0) {
  64. $j. = $CNum [0][$s [1]];
  65. }
  66. }
  67. }
  68. Bit
  69. if ($s [0]!== ") {
  70. $s [0] = (int) $s [0];
  71. if ($s [0]!== 0) {
  72. $j. = $CNum [0][$s [0]]. $CNum [1][0];
  73. } else {
  74. $j. = $CNum [0][0];
  75. }
  76. }
  77. $j. = $CNum [2][$i/4];
  78. Array_unshift ($chinese, $j);
  79. }
  80. $chs = Implode (' ', $chinese);
  81. if ($FL) {
  82. $chs. = ' point ';
  83. For ($i =0, $j =strlen ($FL), $i < $j; $i + +) {
  84. $t = (int) $FL [$i];
  85. $chs. = $str [0][$t];
  86. }
  87. }
  88. return $chs;
  89. }
Copy Code
  1. function Number2chinese ($num, $m = 1) {
  2. Switch ($m) {
  3. Case 0:
  4. $CNum = Array (
  5. Array (' 0 ', ' one ', ' II ', ' three ', ' establishments ', ' Wu ', ' Lu ', ' qi ', ' ba ', ' JIU '),
  6. Array (', ' Pick ', ' bai ', ' thousand '),
  7. Array (', ' million ', ' Yi ', ' billions ')
  8. );
  9. Break
  10. Default
  11. $CNum = Array (
  12. Array (' 0 ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six ', ' seven ', ' eight ', ' nine '),
  13. Array (' ', ' ten ', ' hundred ', ' thousand '),
  14. Array (', ' million ', ' billion ', ' trillion ')
  15. );
  16. Break
  17. }
  18. $cNum = Array (' 0 ', ' one ', ' two ', ' three ', ' four ', ' V ', ' VI ', ' VII ', ' VIII ', ' IX ');
  19. if (Is_integer ($num)) {
  20. $int = (string) $num;
  21. } else if (Is_numeric ($num)) {
  22. $num = Explode ('. ', (String) floatval ($num));
  23. $int = $num [0];
  24. $FL = Isset ($num [1])? $num [1]: FALSE;
  25. }
  26. Length
  27. $len = strlen ($int);
  28. Chinese
  29. $chinese = Array ();
  30. Reversed number
  31. $str = Strrev ($int);
  32. for ($i = 0; $i < $len; $i +=4) {
  33. $s = Array (0=> $str [$i], 1=> $str [$i +1], 2=> $str [$i +2], 3=> $str [$i +3]);
  34. $j = ";
  35. Thousands
  36. if ($s [3]!== ") {
  37. $s [3] = (int) $s [3];
  38. if ($s [3]!== 0) {
  39. $j. = $CNum [0][$s [3]]. $CNum [1][3];
  40. } else {
  41. if ($s [2]! = 0 | | $s [1]! = 0 | | $s [0]!=0] {
  42. $j. = $CNum [0][0];
  43. }
  44. }
  45. }
  46. Hundred
  47. if ($s [2]!== ") {
  48. $s [2] = (int) $s [2];
  49. if ($s [2]!== 0) {
  50. $j. = $CNum [0][$s [2]]. $CNum.
  51. } else {
  52. if ($s [3]!=0 && ($s [1]! = 0 | | $s [0]!=0]) {
  53. $j. = $CNum [0][0];
  54. }
  55. }
  56. }
  57. Ten
  58. if ($s [1]!== ") {
  59. $s [1] = (int) $s [1];
  60. if ($s [1]!== 0) {
  61. $j. = $CNum [0][$s [1]]. $CNum [1][1];
  62. } else {
  63. if ($s [0]!=0 && $s [2]! = 0) {
  64. $j. = $CNum [0][$s [1]];
  65. }
  66. }
  67. }
  68. Bit
  69. if ($s [0]!== ") {
  70. $s [0] = (int) $s [0];
  71. if ($s [0]!== 0) {
  72. $j. = $CNum [0][$s [0]]. $CNum [1][0];
  73. } else {
  74. $j. = $CNum [0][0];
  75. }
  76. }
  77. $j. = $CNum [2][$i/4];
  78. Array_unshift ($chinese, $j);
  79. }
  80. $chs = Implode (' ', $chinese);
  81. if ($FL) {
  82. $chs. = ' point ';
  83. For ($i =0, $j =strlen ($FL), $i < $j; $i + +) {
  84. $t = (int) $FL [$i];
  85. $chs. = $str [0][$t];
  86. }
  87. }
  88. return $chs;
  89. }
Copy Code
  • 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.