dec_to_roman

Downloaddec_to_roman(dec)   Returns the given integer expressed as a roman numeral string.
/*
**  Usage:
**      dec_to_roman(dec)
**
**  Arguments:
**      dec         integer from 1 to 4999
**
**  Returns:
**      the given number expressed as a roman numeral string,
**      or an empty string on error
**
**  GMLscripts.com
*/

{
    var n,ones,tens,huns,thos,roman;
    n = floor(argument0);
    if ((n < 0) || (n > 4999)) return "";
    n = string_replace_all(string_format(n,4,0)," ","0");
    ones = "    I   II  III IV  V   VI  VII VIIIIX  ";
    tens = "    X   XX  XXX XL  L   LX  LXX LXXXXC  ";
    huns = "    C   CC  CCC CD  D   DC  DCC DCCCCM  ";
    thos = "    M   MM  MMM MMMM";
    roman  = string_copy(thos,4*real(string_char_at(n,1))+1,4);
    roman += string_copy(huns,4*real(string_char_at(n,2))+1,4);
    roman += string_copy(tens,4*real(string_char_at(n,3))+1,4);
    roman += string_copy(ones,4*real(string_char_at(n,4))+1,4);
    roman  = string_replace_all(roman," ","");
    return roman;
}

Click if you've used this script[Please Login]
Projects: 4


comments powered by Disqus