Skip to content

Instantly share code, notes, and snippets.

@cahsowan
Created April 21, 2015 04:16
Show Gist options
  • Save cahsowan/d315d54a59e4f14a6bab to your computer and use it in GitHub Desktop.
Save cahsowan/d315d54a59e4f14a6bab to your computer and use it in GitHub Desktop.
Fungsi Terbilang Dengan PHP
<?php
function terbilang($x) {
$angka = ["", "satu", "dua", "tiga", "empat", "lima", "enam", "tujuh", "delapan", "sembilan", "sepuluh", "sebelas"];
if ($x < 12)
return " " . $angka[$x];
elseif ($x < 20)
return terbilang($x - 10) . " belas";
elseif ($x < 100)
return terbilang($x / 10) . " puluh" . terbilang($x % 10);
elseif ($x < 200)
return "seratus" . terbilang($x - 100);
elseif ($x < 1000)
return terbilang($x / 100) . " ratus" . terbilang($x % 100);
elseif ($x < 2000)
return "seribu" . terbilang($x - 1000);
elseif ($x < 1000000)
return terbilang($x / 1000) . " ribu" . terbilang($x % 1000);
elseif ($x < 1000000000)
return terbilang($x / 1000000) . " juta" . terbilang($x % 1000000);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Fungsi Terbilang dengan PHP</title>
</head>
<body>
<form action="" method="POST">
<input type="text" name="number">
<button>Terbilang</button>
</form>
<hr>
<?php
if ($_POST) {
echo number_format($_POST['number'], 0, ",", ".");
echo " (";
echo ucwords(terbilang($_POST['number']));
echo ")";
}
?>
</body>
</html>
@khoesoema
Copy link

Terima Kasih Banyak, bro, sangat membantu dan mempercepat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment