B-219 Sec-55 Noida, India
+918010221733

Convert Digits To Roman Numbers in PHP

Use this function to convert digits to roman numbers in php

<?php

function romanic_number($integer, $upcase = false)
{
   
    if($upcase==true){
        $table = 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);
    }
    else{
        $table = 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);
    }
   
   
   
   
    $return = ”;
    while($integer > 0)
    {
        foreach($table as $rom=>$arb)
        {
            if($integer >= $arb)
            {
                $integer -= $arb;
                $return .= $rom;
                break;
            }
        }
    }

    return $return;
}

?>

(Visited 125 times, 1 visits today)

Leave a reply

You must be logged in to post a comment.