Beyond_Beyaan.Utility.ConvertNumberToRomanNumberical C# (CSharp) Метод

ConvertNumberToRomanNumberical() публичный статический Метод

Converts from a numeric value to roman numbers
public static ConvertNumberToRomanNumberical ( int value ) : string
value int Value to convert
Результат string
        public static string ConvertNumberToRomanNumberical(int value)
        {
            //This algorithm is courtesy of
            //http://www.blackwasp.co.uk/NumberToRoman.aspx

            if (value < 0 || value > 3999)
            {
                throw new ArgumentException("Value must be in the range 0 - 3,999.");
            }
            if (value == 0)
            {
                return "N";
            }
            int[] values = new int[] { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 };
            string[] numerals = new string[] { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" };

            StringBuilder result = new StringBuilder();

            // Loop through each of the values to diminish the number
            for (int i = 0; i < 13; i++)
            {
                // If the number being converted is less than the test value, append
                // the corresponding numeral or numeral pair to the resultant string
                while (value >= values[i])
                {
                    value -= values[i];
                    result.Append(numerals[i]);
                }
            }

            return result.ToString();
        }