Created
November 25, 2020 03:22
-
-
Save baralogi/6bb7ff2d9ce16d01b79f5a20026b19ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function penyebut($nilai) { | |
$nilai = abs($nilai); | |
$huruf = array("", "satu", "dua", "tiga", "empat", "lima", "enam", "tujuh", "delapan", "sembilan", "sepuluh", "sebelas"); | |
$temp = ""; | |
if ($nilai < 12) { | |
$temp = " ". $huruf[$nilai]; | |
} else if ($nilai <20) { | |
$temp = penyebut($nilai - 10). " belas"; | |
} else if ($nilai < 100) { | |
$temp = penyebut($nilai/10)." puluh". penyebut($nilai % 10); | |
} else if ($nilai < 200) { | |
$temp = " seratus" . penyebut($nilai - 100); | |
} else if ($nilai < 1000) { | |
$temp = penyebut($nilai/100) . " ratus" . penyebut($nilai % 100); | |
} else if ($nilai < 2000) { | |
$temp = " seribu" . penyebut($nilai - 1000); | |
} else if ($nilai < 1000000) { | |
$temp = penyebut($nilai/1000) . " ribu" . penyebut($nilai % 1000); | |
} else if ($nilai < 1000000000) { | |
$temp = penyebut($nilai/1000000) . " juta" . penyebut($nilai % 1000000); | |
} else if ($nilai < 1000000000000) { | |
$temp = penyebut($nilai/1000000000) . " milyar" . penyebut(fmod($nilai,1000000000)); | |
} else if ($nilai < 1000000000000000) { | |
$temp = penyebut($nilai/1000000000000) . " trilyun" . penyebut(fmod($nilai,1000000000000)); | |
} | |
return $temp; | |
} | |
function terbilang($nilai) { | |
if($nilai<0) { | |
$hasil = "minus ". trim(penyebut($nilai)); | |
} else { | |
$hasil = trim(penyebut($nilai)); | |
} | |
return $hasil; | |
} | |
echo ucwords(terbilang(10000))." Rupiah"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment