digital conversion chinese

WBOY
Release: 2016-07-25 09:05:58
Original
980 people have browsed it
  1. class TransFormNumber{
  2. public $chinaData = array('1'=>'壹','2'=>'二','3'=>'三', '4'=>'Si','5'=>'Wu','6'=>'Lu','7'=>'Qi','8'=>'Eight', '9'=>'玖');
  3. public $chinaDataInt = array('1'=>'Yuan','2'=>'Shi','3'=>'Hundred','4 '=>'Qian','5'=>'Ten thousand','6'=>'Shi','7'=>'Hundred','8'=>'Qian','9 '=>'Billion','10'=>'Shi','11'=>'Hundred','12'=>'Qian','13'=>'Ten thousand');
  4. public $chinaDataFloat = array('1'=>'angle','2'=>'fen');
  5. private $Intnumber; // string
  6. private $Floatnumber; // string
  7. public $error = array( '0'=>'zero','def'=>'Data format not supported');
  8. public function __construct($intnumber,$floatnumber){
  9. $this->Intnumber = $intnumber;
  10. $ this->Floatnumber = $floatnumber;
  11. }
  12. /*13-digit 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,''),'zero');
  26. if(substr($this->Intnumber,$len-1,1) == 0){
  27. $str.='元';
  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[] = 'zero';
  44. }
  45. }else{
  46. $data[] = '10,000';
  47. continue;
  48. }
  49. continue ;
  50. }
  51. if($i%8 == 0 && $i != 0 && $oneData == 0){
  52. $data[] = '100 million';
  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 [] = 'zero';
  60. }
  61. }else{
  62. if(substr($intData,$i-1,1) !=0 && $i !=3 && $i != 8){
  63. $data[] = 'zero';
  64. }else{
  65. if($i == 3 && substr($intData,$i,1) == 0 && substr($intData,$i-1,1) != 0){
  66. $data[] = 'zero';
  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. //Tightly supports 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[] = 'zero';
  84. }else{
  85. $data [] = $this->chinaData[$floatData{0}].$this->chinaDataFloat[1];
  86. }
  87. if($floatDataBB媪!= 0 ){
  88. $data[] = $this-> ;chinaData[$floatDataBB媪].$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


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!