PHP function for converting digital amount to Chinese capital amount

Source: Internet
Author: User
  1. /**
  2. * A function of converting a digital amount into a Chinese capital amount
  3. *string Int $num lowercase number or lowercase string to convert
  4. *return Capital Letters
  5. * Decimal place is two digits
  6. **/
  7. function Get_amount ($num) {
  8. $c 1 = "0 One and three Woolu qi Ba Jiu";
  9. $c 2 = "split-angle element pick Bai thousand thousand million";
  10. $num = Round ($num, 2);
  11. $num = $num * 100;
  12. if (strlen ($num) > 10) {
  13. Return "The data is too long, there is no such big money, check under";
  14. }
  15. $i = 0;
  16. $c = "";
  17. while (1) {
  18. if ($i = = 0) {
  19. $n = substr ($num, strlen ($num)-1, 1);
  20. } else {
  21. $n = $num% 10;
  22. }
  23. $p 1 = substr ($c 1, 3 * $n, 3);
  24. $p 2 = substr ($c 2, 3 * $i, 3);
  25. if ($n! = ' 0 ' | | ($n = = ' 0 ' && ($p 2 = = ' billion ' | | $p 2 = = ' million ' | | $p 2 = = ' Yuan '))) {
  26. $c = $p 1. $p 2. $c;
  27. } else {
  28. $c = $p 1. $c;
  29. }
  30. $i = $i + 1;
  31. $num = $num/10;
  32. $num = (int) $num;
  33. if ($num = = 0) {
  34. Break
  35. }
  36. }
  37. $j = 0;
  38. $slen = strlen ($c);
  39. while ($j < $slen) {
  40. $m = substr ($c, $j, 6);
  41. if ($m = = ' 0 Yuan ' | | $m = = ' 0 ' | | $m = = ' 0 ' | | $m = = ' 00 ') {
  42. $left = substr ($c, 0, $j);
  43. $right = substr ($c, $j + 3);
  44. $c = $left. $right;
  45. $j = $j-3;
  46. $slen = $slen-3;
  47. }
  48. $j = $j + 3;
  49. }
  50. if (substr ($c, strlen ($c)-3, 3) = = ' 0 ') {
  51. $c = substr ($c, 0, strlen ($c)-3);
  52. }
  53. if (empty ($c)) {
  54. Return "0 yuan whole";
  55. }else{
  56. Return $c. "Whole";
  57. }
  58. }
Copy Code

Convert to, PHP
  • 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.