how to convert a number into roman numeral in visual C#
how convert number roman numeral in visual c#
there's no standard method this, have write it.
for example, can try (simple , recursive):
public static string toroman(int number) { if ((number < 0) || (number > 3999)) throw new argumentoutofrangeexception("value must between 1 , 3999"); if (number < 1) return string.empty; if (number >= 1000) return "m" + toroman(number - 1000); if (number >= 900) return "cm" + toroman(number - 900); //edit: i've typed 400 instead 900 if (number >= 500) return "d" + toroman(number - 500); if (number >= 400) return "cd" + toroman(number - 400); if (number >= 100) return "c" + toroman(number - 100); if (number >= 90) return "xc" + toroman(number - 90); if (number >= 50) return "l" + toroman(number - 50); if (number >= 40) return "xl" + toroman(number - 40); if (number >= 10) return "x" + toroman(number - 10); if (number >= 9) return "ix" + toroman(number - 9); if (number >= 5) return "v" + toroman(number - 5); if (number >= 4) return "iv" + toroman(number - 4); if (number >= 1) return "i" + toroman(number - 1); throw new argumentoutofrangeexception("value must between 1 , 3999"); }
Visual Studio Languages , .NET Framework > Visual C#
Comments
Post a Comment