/// <summary> /// Converts an integer into a roman numeral string. /// </summary> /// <param name="x"></param> /// <returns></returns> /// <remarks></remarks> public static string ToNumerals(int x, RomanNumeralStyle style = RomanNumeralStyle.Modern) { if (x == 0) { return("NVL"); } if (x < 0) { x = -x; } string s = "" + x; string @out = ""; char[] ch = s.ToCharArray(); switch (ch.Length) { case 1: { return(FirstToNum(ch[0], style)); } case 2: { return(SecondToNum(ch[0], style) + FirstToNum(ch[1], style)); } case 3: { return(ThirdToNum(ch[0], style) + SecondToNum(ch[1], style) + FirstToNum(ch[2], style)); } case var @case when @case >= 4: { return(FourthToNum(s) + ThirdToNum(ch[1], style) + SecondToNum(ch[2], style) + FirstToNum(ch[3], style)); } } return(null); }
/// <summary> /// Converts the third integer (from right-to-left) into a roman numeral. /// </summary> /// <param name="ch"></param> /// <returns></returns> /// <remarks></remarks> private static string ThirdToNum(char ch, RomanNumeralStyle style = RomanNumeralStyle.Modern) { return(style == RomanNumeralStyle.Antique ? ThirdNumsAntique[int.Parse(Conversions.ToString(ch))] : ThirdNums[int.Parse(Conversions.ToString(ch))]); }