PHP- BItlang


SUBMITTED BY: Guest

DATE: Dec. 27, 2013, 5:01 a.m.

FORMAT: PHP

SIZE: 1.6 kB

HITS: 796

  1. function kekata($x) {
  2. $x = abs($x);
  3. $angka = array("", "satu", "dua", "tiga", "empat", "lima", "enam", "tujuh", "delapan", "sembilan", "sepuluh", "sebelas");
  4. $temp = "";
  5. if ($x <12) {
  6. $temp = " ". $angka[$x];
  7. } else if ($x <20) {
  8. $temp = kekata($x - 10). " belas";
  9. } else if ($x <100) {
  10. $temp = kekata($x/10)." puluh". kekata($x % 10);
  11. } else if ($x <200) {
  12. $temp = " seratus" . kekata($x - 100);
  13. } else if ($x <1000) {
  14. $temp = kekata($x/100) . " ratus" . kekata($x % 100);
  15. } else if ($x <2000) {
  16. $temp = " seribu" . kekata($x - 1000);
  17. } else if ($x <1000000) {
  18. $temp = kekata($x/1000) . " ribu" . kekata($x % 1000);
  19. } else if ($x <1000000000) {
  20. $temp = kekata($x/1000000) . " juta" . kekata($x % 1000000);
  21. } else if ($x <1000000000000) {
  22. $temp = kekata($x/1000000000) . " milyar" . kekata(fmod($x,1000000000));
  23. } else if ($x <1000000000000000) {
  24. $temp = kekata($x/1000000000000) . " trilyun" . kekata(fmod($x,1000000000000));
  25. }
  26. return $temp;
  27. }
  28. function terbilang($x, $style=4) {
  29. if($x < 0) {
  30. $hasil = "minus " . trim(kekata($x));
  31. } else {
  32. $hasil = trim(kekata($x));
  33. }
  34. switch ($style) {
  35. case 1:
  36. $hasil = strtoupper($hasil);
  37. break;
  38. case 2:
  39. $hasil = strtolower($hasil);
  40. break;
  41. case 3:
  42. $hasil = ucwords($hasil);
  43. break;
  44. default:
  45. $hasil = ucfirst($hasil);
  46. break;
  47. }
  48. return $hasil;
  49. }

comments powered by Disqus