That's a nice exercise, here's my solution in php (from 1 to 999):
<?php
$decimal='222';
$romans=array('I','V','X','L','C','D','M');
$digits=array_reverse(str_split($decimal));
$x=0;
$final="";
foreach($digits as $d){
if($d==4){
$v=$romans[$x].$romans[$x+1];
}
else if($d==9){
$v=$romans[$x].$romans[$x+2];
}
else{
$n=str_pad("", $d , $romans[$x]);
$n5=str_pad("", 5 , $romans[$x]);
$v=str_replace($n5,$romans[$x+1],$n);
}
$x+=2;
$final=$v.$final;
}
echo $final;
?>
Here's a
demo