You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.3 KiB
PHP
36 lines
1.3 KiB
PHP
<?php
|
|
namespace NN\Module;
|
|
|
|
class Text{
|
|
|
|
public static function pad($value, $threshold = 2) {
|
|
return sprintf('%0' . $threshold . 's', $value);
|
|
}
|
|
|
|
public static function rupiah($angka){
|
|
|
|
$hasil_rupiah = "Rp " . number_format($angka,2,',','.');
|
|
return $hasil_rupiah;
|
|
|
|
}
|
|
|
|
public static 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 (new self)->terbilang($x - 10) . " belas";
|
|
elseif ($x < 100)
|
|
return (new self)->terbilang($x / 10) . " puluh" . (new self)->terbilang($x % 10);
|
|
elseif ($x < 200)
|
|
return "seratus" . (new self)->terbilang($x - 100);
|
|
elseif ($x < 1000)
|
|
return (new self)->terbilang($x / 100) . " ratus" . (new self)->terbilang($x % 100);
|
|
elseif ($x < 2000)
|
|
return "seribu" . (new self)->terbilang($x - 1000);
|
|
elseif ($x < 1000000)
|
|
return (new self)->terbilang($x / 1000) . " ribu" . (new self)->terbilang($x % 1000);
|
|
elseif ($x < 1000000000)
|
|
return (new self)->terbilang($x / 1000000) . " juta" . (new self)->terbilang($x % 1000000);
|
|
}
|
|
} |