Source code-nya:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | <?php @$angka = isset($_POST['angka']) ? $_POST['angka'] : "0"; ?> <!DOCTYPE html> <hmtl> <head> <title>SWITCH-KONVERSI ANGKA -> HURUF</title> </head> <body> <form action="konversiAngka-Huruf.php" method="POST"> <table> <tr> <td>Input Angka</td> <td>=</td> <td><input type="text" name="angka" value="<?php echo $angka; ?>"/></td> </tr> </table> <input type="submit" name="submit" value="SUBMIT"/><br/><br/> <?php if ($angka) { echo number_format($angka, 0) . "<br/>"; echo ucwords(Dibaca($angka)); } ?> <?php function Dibaca($x) { $angkaBaca = array("", "satu", "dua", "tiga", "empat", "lima", "enam", "tujuh", "delapan", "sembilan", "sepuluh", "sebelas"); switch ($x) { case ($x < 12): echo " " . $angkaBaca[$x]; break; case ($x < 20): echo $result = Dibaca($x - 10) . " belas"; break; case ($x < 100): echo Dibaca($x / 10); echo " puluh "; echo Dibaca($x % 10); break; case ($x < 200): echo " seratus "; echo Dibaca($x - 100); break; case ($x < 1000): echo Dibaca($x / 100); echo " ratus"; echo Dibaca($x % 100); break; case ($x < 2000): echo " seribu "; echo Dibaca($x - 1000); break; case ($x < 1000000): echo Dibaca($x / 1000); echo " ribu "; echo Dibaca($x % 1000); break; case ($x < 1000000000): echo Dibaca($x / 1000000); echo " juta "; echo Dibaca($x % 1000000); break; } } ?> </form> </body> </hmtl> |
Tampilan hasilnya adalah sebagai berikut:
No comments:
Post a Comment