<?php
/*
Demo fungsi Terbilang untuk mengetahui pembacaan bilangan besar dalam Bahasa Indonesia
Original Source : https://www.malasngoding.com/cara-mudah-membuat-fungsi-terbilang-dengan-php/
Modified to add kuadriliun,kuintiliun, and a form to test the function, suppress deprecated errors, by RPL SMKN 1 Pacitan
*/
error_reporting(E_ALL ^ E_DEPRECATED);
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));
} else if ($nilai < 1000000000000000000) {
$temp = penyebut($nilai/1000000000000000) . " kuadriliun" . penyebut(fmod($nilai,1000000000000000));
} else if ($nilai < 1000000000000000000000) {
$temp = penyebut($nilai/1000000000000000000) . " kuintiliun" . penyebut(fmod($nilai,1000000000000000000));
}
return $temp;
}
function terbilang($nilai) {
if($nilai<0) {
$hasil = "minus ". trim(penyebut($nilai));
} else {
$hasil = trim(penyebut($nilai));
}
return $hasil;
}
if (isset($_POST["bilangan"]) && is_numeric($_POST["bilangan"])) {
echo "<h3>".number_format($_POST["bilangan"], 0,',','.')."</h3>";
echo terbilang($_POST["bilangan"]);
}
?>
<form method="post">
<input type="text" name="bilangan" id="bilangan">
<input type="submit" value="Cek">
</form>
Comments