Invert GMLscripts.com

dec_to_roman

Converts a decimal value to a string of Roman numerals.

roman = dec_to_roman(42);    //  roman == "XLII"
roman = dec_to_roman(1999);  //  roman == "MCMXCIX"
roman = dec_to_roman(2015);  //  roman == "MMXV"
dec_to_roman(num)
Returns a string of Roman numerals representing the given integer.
COPY//
//  Returns a string of Roman numerals representing the given integer.
//
//      num         positive integer less than 5000, real
//
/// GMLscripts.com/license
{
    var roman;
    if ((argument0 < 1) || (argument0 > 4999)) return "";
    roman  = string_copy("    M   MM  MMM MMMM",4*(argument0 div 1000)+1,4);
    roman += string_copy("    C   CC  CCC CD  D   DC  DCC DCCCCM  ",4*((argument0 mod 1000) div 100)+1,4);
    roman += string_copy("    X   XX  XXX XL  L   LX  LXX LXXXXC  ",4*((argument0 mod 100) div 10)+1,4);
    roman += string_copy("    I   II  III IV  V   VI  VII VIIIIX  ",4*(argument0 mod 10)+1,4);
    roman  = string_replace_all(roman," ","");
    return roman;
}

Contributors: xot

GitHub: View · Commits · Blame · Raw