Function Merubah Angka Biasa Menjadi Angka Romawi di PHP

5
(1)

Berikut adalah function untuk merubah angka bisa menjadi angka romawi pada bahasa pemrograman PHP.

	
		 function numberToRomanRepresentation($number) {
		    $map = array('M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400, 'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40, 'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1);
		    $returnValue="";
		    while ($number > 0) {
		        foreach ($map as $roman => $int) {
		            if($number >= $int) {
		                $number -= $int;
		                $returnValue .= $roman;
		                break;
		            }
		        }
		    }
		    return $returnValue;
		}
	

Berikut contoh cara penggunaannya :


$romawi = numberToRomanRepresentation(20);
echo $romawi;


Source link

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.


Notice: ob_end_flush(): failed to send buffer of zlib output compression (0) in /home/breatgem/widiyanata.com/wp-includes/functions.php on line 4755