Advertisement
fadlyshafa

Untitled

Apr 8th, 2020
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1. function penyebut($nilai)
  2.     {
  3.         $nilai = abs($nilai);
  4.         $huruf = array("", "Satu", "Dua", "Tiga", "Empat", "Lima", "Enam", "Tujuh", "Delapan", "Sembilan", "Sepuluh", "Sebelas");
  5.         $temp = "";
  6.         if ($nilai < 12) {
  7.             $temp = " " . $huruf[$nilai];
  8.         } else if ($nilai < 20) {
  9.             $temp = penyebut($nilai - 10) . " Belas";
  10.         } else if ($nilai < 100) {
  11.             $temp = penyebut($nilai / 10) . " Puluh" . penyebut($nilai % 10);
  12.         } else if ($nilai < 200) {
  13.             $temp = " Seratus" . penyebut($nilai - 100);
  14.         } else if ($nilai < 1000) {
  15.             $temp = penyebut($nilai / 100) . " Ratus" . penyebut($nilai % 100);
  16.         } else if ($nilai < 2000) {
  17.             $temp = " Seribu" . penyebut($nilai - 1000);
  18.         } else if ($nilai < 1000000) {
  19.             $temp = penyebut($nilai / 1000) . " Ribu" . penyebut($nilai % 1000);
  20.         } else if ($nilai < 1000000000) {
  21.             $temp = penyebut($nilai / 1000000) . " Juta" . penyebut($nilai % 1000000);
  22.         } else if ($nilai < 1000000000000) {
  23.             $temp = penyebut($nilai / 1000000000) . " Milyar" . penyebut(fmod($nilai, 1000000000));
  24.         } else if ($nilai < 1000000000000000) {
  25.             $temp = penyebut($nilai / 1000000000000) . " Trilyun" . penyebut(fmod($nilai, 1000000000000));
  26.         }
  27.         return $temp;
  28.     }
  29.  
  30.     function terbilang($nilai)
  31.     {
  32.         if ($nilai < 0) {
  33.             $hasil = "minus " . trim(penyebut($nilai));
  34.         } else {
  35.             $hasil = trim(penyebut($nilai));
  36.         }
  37.         return $hasil;
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement