Digital conversion Chinese

Source: Internet
Author: User
<无详细内容>
  1. Class transformnumber{
  2. Public $chinaData = Array (' 1 ' = ' one ', ' 2 ' + ' II ', ' 3 ' = ' three ', ' 4 ' = ') ', ' 5 ' = ' Wu ', ' 6 ' = ' land ', ' 7 ' = ' seven ', ' 8 ' = ' ba ', ' 9 ' = ' jiu ');
  3. Public $chinaDataInt = Array (' 1 ' = = ' Yuan ', ' 2 ' = ' pick ', ' 3 ' = ' ' Bai ', ' 4 ' = ' thousand ', ' 5 ' + ' million ', ' 6 ' = ' ' Pick ', ' 7 ' = ' Bai ', ' 8 ' = ' thousand ', ' 9 ' + ' billion ', ' ten ' = ' pick ', ' one ' and ' Bai ', ' ' A ' and ' thousand ', ' ' + ' (million ');
  4. Public $chinaDataFloat = Array (' 1 ' = ' angle ', ' 2 ' = ' + ');
  5. Private $Intnumber; String
  6. Private $Floatnumber; String
  7. Public $error = Array (' 0 ' = ' 0 ', ' def ' = ' data format not supported ');
  8. Public function __construct ($intnumber, $floatnumber) {
  9. $this->intnumber = $intnumber;
  10. $this->floatnumber = $floatnumber;
  11. }
  12. /*13 bit integer */
  13. Public Function Gettransint () {
  14. $this->intnumber = intval ($this->intnumber);
  15. $len = strlen ($this->intnumber);
  16. if ($len > 13) {
  17. Return $this->errornotice (1);
  18. }
  19. if ($this->intnumber = = 0) {
  20. return $this->errornotice (' def ');
  21. }
  22. $intData = Strrev (substr ($this->intnumber,0, $len));
  23. $data = $this->settransint ($intData, $len);
  24. Krsort ($data);
  25. $STR = RTrim (Join ($data, '), ' 0 ');
  26. if (substr ($this->intnumber, $len -1,1) = = 0) {
  27. $str. = ' Yuan ';
  28. }
  29. Unset ($data);
  30. return $str;
  31. }
  32. Public Function gettransfloat () {
  33. return $this->settransfloat ($this->floatnumber,strlen ($this->floatnumber));
  34. }
  35. Private Function Settransint ($intData, $pos) {
  36. for ($i =0; $i < $pos; $i + +) {
  37. $oneData = substr ($intData, $i, 1);
  38. if ($i = = 4 | | ($i%8) = = 4) && $oneData = = 0) {
  39. if (substr ($intData, $i +1,1) = = 0 && substr ($intData, $i +2,1) = = 0 && substr ($intData, $i +3,1) = = 0) {
  40. if (substr ($intData, $i -1,1) = = 0) {
  41. Continue
  42. }else{
  43. $data [] = ' 0 ';
  44. }
  45. }else{
  46. $data [] = ' million ';
  47. Continue
  48. }
  49. Continue
  50. }
  51. if ($i%8 = = 0 && $i! = 0 && $oneData = = 0) {
  52. $data [] = ' billion ';
  53. }
  54. if ($oneData = = 0) {
  55. if (($i = = 4 | | $i = = 7)) {
  56. if ((substr ($intData, $i -1,1) ==0)) {
  57. Continue
  58. }else{
  59. $data [] = ' 0 ';
  60. }
  61. }else{
  62. if (substr ($intData, $i -1,1)!=0 && $i!=3 && $i! = 8) {
  63. $data [] = ' 0 ';
  64. }else{
  65. if ($i = = 3 && substr ($intData, $i, 1) = = 0 && substr ($intData, $i -1,1)! = 0) {
  66. $data [] = ' 0 ';
  67. }
  68. }
  69. }
  70. }else{
  71. $data [] = $this->chinadata[$oneData]. $this->chinadataint[$i +1];
  72. }
  73. }
  74. Unset ($intData, $oneData, $i);
  75. return $data;
  76. }
  77. Tight support for two decimal places
  78. Private Function Settransfloat ($floatData, $pos) {
  79. if ($pos > 2) {
  80. return $this->errornotice (' def ');
  81. }
  82. if ($floatData {0} = = 0) {
  83. $data [] = ' 0 ';
  84. }else{
  85. $data [] = $this->chinadata[$floatData {0}]. $this->chinadatafloat[1];
  86. }
  87. if ($floatDataBB Puma! = 0) {
  88. $data [] = $this->chinadata[$floatDataBB Puma]. $this->chinadatafloat[2];
  89. }
  90. Return implode (", $data);
  91. }
  92. Public Function Errornotice ($error) {
  93. return $this->error[$error];
  94. }
  95. }
  96. $num = new Transformnumber (' 100228030 ', ' 80 ');
  97. echo $num->gettransint ();
  98. echo $num->gettransfloat ();
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.