Arsip: SayNumber


by myitanium in TipDanTrik more 11 years ago 3218
Ini caranya membuat angka menjadi kata-kata dalam bahasa indonesia.
Fungsi ditulis dengan function mySQL. Seharusnya bisa diconvert dengan mudah ke Database server lain.
CREATE FUNCTION SayNumber(inputnumber int) RETURNS varchar(100)
BEGIN
DECLARE number, numstr varchar(100);
SET number=inputnumber;
SET numstr=' ';
WHILE LENGTH(number) >= 1 DO
IF LEFT(number,1)= 2 THEN SET numstr=CONCAT(numstr,'Dua ' ); END IF;
IF LEFT(number,1)= 3 THEN SET numstr=CONCAT(numstr,'Tiga ' ); END IF;
IF LEFT(number,1)= 4 THEN SET numstr=CONCAT(numstr,'Empat ' ); END IF;
IF LEFT(number,1)= 5 THEN SET numstr=CONCAT(numstr,'Lima ' ); END IF;
IF LEFT(number,1)= 6 THEN SET numstr=CONCAT(numstr,'Enam ' );END IF;
IF LEFT(number,1)= 7 THEN SET numstr=CONCAT(numstr,'Tujuh ' ); END IF;
IF LEFT(number,1)= 8 THEN SET numstr=CONCAT(numstr,'Delapan ' ); END IF;
IF LEFT(number,1)= 9 THEN SET numstr=CONCAT(numstr,'Sembilan ' ); END IF;
IF LEFT(number,1 )=1 THEN
IF LENGTH(number)=4 THEN SET numstr=CONCAT(numstr,'Seribu ' ); END IF;
IF LENGTH(number)=3 THEN SET numstr=CONCAT(numstr,'Seratus ' ); END IF;
IF LENGTH(number)=2 THEN SET numstr=CONCAT(numstr,'Sepuluh ' ); END IF;
IF LENGTH(number)=1 THEN SET numstr=CONCAT(numstr,'Satu ' ); END IF;
END IF;
IF LEFT(number,1)>1 THEN
IF LENGTH(number)=4 THEN SET numstr=CONCAT(numstr,'Ribu ' ); END IF;
IF LENGTH(number)=3 THEN SET numstr=CONCAT(numstr,'Ratus ' ); END IF;
IF LENGTH(number)=2 THEN SET numstr=CONCAT(numstr,'Puluh ' ); END IF;
END IF;
SET number=RIGHT(number,(LENGTH(number)-1 ));
END WHILE;
RETURN numstr;
END
Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com