Home > Backend Development > PHP Tutorial > This function only supports converting integer lowercase amounts to Chinese uppercase letters.

This function only supports converting integer lowercase amounts to Chinese uppercase letters.

WBOY
Release: 2016-07-25 09:07:19
Original
1420 people have browsed it
  1. /*

  2. Only supports converting integer lowercase amounts to Chinese uppercase
  3. */
  4. class ChineseNumber
  5. {
  6. //var $basical=array(0=>"zero" ,"one","two","three","four","five","six","seven","eight","nine");
  7. var $basical=array(0=>" Zero", "one", "two", "three", "four", "five", "Lu", "旒", "eight", "玖");
  8. //var $advanced=array(1 =>"十","百","千");
  9. var $advanced=array(1=>"十","百","千");
  10. var $top=array(1=> ;"10,000","100 million");

  11. var $level; // Use 4 digits as one level

  12. // First implement the 10,000 level Number conversion

  13. function small2big($number)
  14. {
  15. if ($number>999999999999) // Can only handle hundreds of billions.
  16. return "The number is too large to handle. Sorry!";
  17. if ($number==0)
  18. return "zero";

  19. for($this->level=0; $number>0.0001;$this->level++,$number=floor($number / 10000))

  20. {
  21. // For Chinese, it should be a group of 4 digits.
  22. // The four variables correspond to units, tens, hundreds, and thousands respectively.
  23. $n1=substr($number,-1,1);
  24. if($number>9)
  25. $n2=substr($number,-2,1);
  26. else
  27. $n2=0;
  28. if($ number>99)
  29. $n3=substr($number,-3,1);
  30. else
  31. $n3=0;
  32. if($number>999)
  33. $n4=substr($number,-4,1);
  34. else
  35. $n4=0;

  36. if($n4)

  37. $parsed[$this->level].=$this->basical[$n4].$this- >advanced[3];
  38. else
  39. if(($number/10000)>=1) // The thousands digit is 0 and the value is greater than 9999
  40. $parsed[$this->level].="zero ";
  41. if($n3)
  42. $parsed[$this->level].=$this->basical[$n3].$this->advanced[2];
  43. else
  44. if(!ereg( "Zero$",$parsed[$this->level]) && ($number / 1000)>=1) //There will be no two consecutive "zeros"
  45. $parsed[$this->level ].="zero";
  46. if($n2)
  47. $parsed[$this->level].=$this->basical[$n2].$this->advanced[1];
  48. else
  49. if(!ereg("zero$",$parsed[$this->level]) && ($number / 100)>=1) //There will be no two consecutive "zeros"
  50. $parsed[$ this->level].="zero";
  51. if($n1)
  52. $parsed[$this->level].=$this->basical[$n1];
  53. }
  54. for($this- >level-=1;$this->level>=0;$this->level--)
  55. {
  56. $result.=$parsed[$this->level].$this->top [$this->level];
  57. }

  58. if(ereg("zero$",$result))

  59. $result=substr($result,0,strlen($result) -2);

  60. return $result;

  61. }
  62. };

  63. $big=new ChineseNumber();

  64. echo $big->small2big( 1311);
  65. ?>

Copy code


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