Home > Backend Development > PHP Tutorial > PHP function to convert numerical amounts into Chinese capital amounts

PHP function to convert numerical amounts into Chinese capital amounts

WBOY
Release: 2016-07-25 08:45:10
Original
1255 people have browsed it
  1. /**
  2. *Function to convert numeric amounts into Chinese uppercase amounts
  3. *String Int $num Lowercase numbers or lowercase strings to be converted
  4. *return uppercase letters
  5. *Two decimal places
  6. **/
  7. function get_amount($num){
  8. $c1 = "zero one two three four five land seven hundred and eighty nine";
  9. $c2 = "cents one hundred thousand ten thousand Hundreds of billions";
  10. $num = round($num, 2);
  11. $num = $num * 100;
  12. if (strlen($num) > 10) {
  13. return "The data is too long, not so big Money, check it out";
  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 == '100 million' || $p2 == '10,000' || $p2 = = '元'))) {
  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 yuan' || $m == 'zero thousand' || $m = = '000 million' || $m == '000') {
  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) == 'zero') {
  51. $c = substr($c, 0, strlen($c)-3);
  52. }
  53. if (empty($c)) {
  54. return "zero Yuan Zheng";
  55. }else{
  56. return $c . "Zheng";
  57. }
  58. }
Copy code


Convert to, PHP


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