quike88
Código PHP:
Ver original<?php
function romanNumber($num) {
$romans = array(1=>'I',4=>'IV',5=>'V',9=>'IX',10=>'X',40=>'XL',50=>'L',90=>'XC',100=>'C',400=>'CD',500=>'D',900=>'CM',1000=>'M'); $romanNumber='';
$i=10;
while($num>0) {
$roman='';
$rom=$num%$i;
if($rom!=0){
if(!isset($romans[$rom])){ $romdec=$rom/($i/10);
if($romdec<5){
for($j=1;$j<=$romdec;$j++)
$roman.=$romans[($i/10)];
}
else {
$roman=$romans[5*($i/10)];
$romdec-=5;
for($j=1;$j<=$romdec;$j++)
$roman.=$romans[($i/10)];
}
$romanNumber=$roman.$romanNumber;
}
else
$romanNumber=$romans[$rom].$romanNumber;
}
$i*=10;
}
return $romanNumber;
}
?>