3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function romToDec ($dec) { $return = ''; while ($dec >= 1000) { $dec -= 1000; $return .= 'M'; } if ($dec >= 900) { $dec -= 900; $return .= 'CM'; } if ($dec >= 500) { $dec -= 500; $return .= 'D'; } if ($dec >= 400) { $dec -= 400; $return .= 'CD'; } while ($dec >= 100) { $dec -= 100; $return .= 'C'; } if ($dec >= 90) { $dec -= 90; $return .= 'XC'; } if ($dec >= 50) { $dec -= 50; $return .= 'L'; } if ($dec >= 40) { $dec -= 40; $return .= 'XL'; } while ($dec >= 10) { $dec -= 10; $return .= 'X'; } if ($dec == 9) { $dec = 0; $return .= 'IX'; } if ($dec >= 5) { $dec -= 5; $return .= 'V'; } if ($dec == 4) { $dec = 0; $return .= 'IV'; } while ($dec >= 1) { $dec -= 1; $return .= 'I'; } return $return; } $tests = array(1, 999, 2016, 23458, 104696); foreach ($tests as $test) { echo $test.' → '.romToDec($test)."\n"; } ?>
Output for 5.3.22 - 7.2.0
1 → I 999 → CMXCIX 2016 → MMXVI 23458 → MMMMMMMMMMMMMMMMMMMMMMMCDLVIII 104696 → MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMDCXCVI