Last active
November 10, 2022 03:51
-
-
Save rindrasakti/d2c6c69ea45d50c48355754f952893f2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
CREATE OR REPLACE FUNCTION terbilang(angka numeric) | |
RETURNS character varying language plpgsql AS | |
$$ | |
DECLARE | |
kata varchar[] = array['satu', 'dua', 'tiga', 'empat', 'lima', 'enam', 'tujuh', 'delapan', 'sembilan', 'sepuluh', 'sebelas']; | |
kalimat varchar = 'Out of range!'; | |
begin | |
angka = abs(angka); | |
if (angka < 12) then | |
kalimat = kata[angka]; | |
elseif (angka < 20) then | |
kalimat = concat(terbilang(trunc(angka - 10)), ' belas '); | |
elseif (angka < (10^2)) then | |
kalimat = concat(terbilang(trunc(angka / 10)), ' puluh ', terbilang(angka::numeric % 10)); | |
elseif (angka < 200) then | |
kalimat = concat(' seratus ', terbilang(trunc(angka - (10^2)))); | |
elseif (angka < (10^3)) then | |
kalimat = concat(terbilang(trunc(angka / (10^2))), ' ratus ', terbilang(angka::numeric % (10^2))); | |
elseif (angka < 2000) then | |
kalimat = concat(' seribu ', terbilang(angka - (10^3))); | |
elseif (angka < (10^6)) then | |
kalimat = concat(terbilang(trunc(angka / (10^3))), ' ribu ', terbilang(angka::numeric % (10^3))); | |
elseif (angka < (10^9)) then | |
kalimat = concat(terbilang(trunc(angka / (10^6))), ' juta ', terbilang(angka::numeric % (10^6))); | |
elseif (angka < (10^12)) then | |
kalimat = concat(terbilang(trunc(angka / (10^9))), ' milyar ', terbilang(angka::numeric % (10^9))); | |
elseif (angka < (10^15)) then | |
kalimat = concat(terbilang(trunc(angka / (10^12))), ' triliun ', terbilang(angka::numeric % (10^12))); | |
elseif (angka < (10^18)) then | |
kalimat = concat(terbilang(trunc(angka / (10^15))), ' kuadriliun ', terbilang(angka::numeric % (10^15))); | |
elseif (angka < (10^21)) then | |
kalimat = concat(terbilang(trunc(angka / (10^18))), ' kuantiliun ', terbilang(angka::numeric % (10^18))); | |
elseif (angka < (10^24)) then | |
kalimat = concat(terbilang(trunc(angka / (10^21))), ' sekstiliun ', terbilang(angka::numeric % (10^21))); | |
elseif (angka < (10^27)) then | |
kalimat = concat(terbilang(trunc(angka / (10^24))), ' septiliun ', terbilang(angka::numeric % (10^24))); | |
elseif (angka < (10^30)) then | |
kalimat = concat(terbilang(trunc(angka / (10^27))), ' oktiliun ', terbilang(angka::numeric % (10^27))); | |
elseif (angka < (10^33)) then | |
kalimat = concat(terbilang(trunc(angka / (10^30))), ' noniliun ', terbilang(angka::numeric % (10^30))); | |
elseif (angka < (10^36)) then | |
kalimat = concat(terbilang(trunc(angka / (10^33))), ' desiliun ', terbilang(angka::numeric % (10^33))); | |
end if; | |
return trim(kalimat); | |
end | |
$$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment