PHP function for converting numeric amount to Chinese capital amount

Source: Internet
Author: User
PHP function for converting numeric amount to Chinese capital amount

  1. /**
  2. * Function for converting a numeric amount to a Chinese capital amount
  3. * String Int $ num the lowercase number or lowercase String to be converted
  4. * Return uppercase letters
  5. * Two decimal places
  6. **/
  7. Function get_amount ($ num ){
  8. $ C1 = "";
  9. $ C2 = "yuanqibaibaibaibaibaibaibaibaibaibaibaibaibaibaibaibaibaibaibaibaibaiyi ";
  10. $ Num = round ($ num, 2 );
  11. $ Num = $ num * 100;
  12. If (strlen ($ num)> 10 ){
  13. Return "the data is too long. if you don't have the money, check ";
  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. $ P1 = substr ($ c1, 3 * $ n, 3 );
  24. $ P2 = substr ($ c2, 3 * $ I, 3 );
  25. If ($ n! = '0' | ($ n = '0' & ($ p2 = '000000' | $ p2 = '000000' | $ p2 =' yuan '))) {
  26. $ C = $ p1. $ p2. $ c;
  27. } Else {
  28. $ C = $ p1. $ 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 = 'zero meta' | $ m = '000000' | $ m = '000000' | $ m = 'zero-zero '){
  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 "zero RMB ";
  55. } Else {
  56. Return $ c. "whole ";
  57. }
  58. }



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.