Not sure where I got this, so my apologies to the original author, but it's been a pretty useful function. Of course, you might want to wrap this with some error handling and validation code, but here's a good start for you...
private string GetRomanNumber(int number)
{
string[] ArabicNums = new string[] {"1", "4", "5", "9", "10", "40", "50", "90", "100", "400", "500", "900", "1000"};
string[] RomanNums = new string[] {"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};
int ArabicUpper = ArabicNums.GetUpperBound(0);
int ArabicLower = ArabicNums.GetLowerBound(0);
string Output = "";
for (int i = ArabicUpper; i >= ArabicLower; i--)
while (number >= Convert.ToInt32(ArabicNums[i]))
number -= Convert.ToInt32(ArabicNums[i]);
Output += RomanNums[i];
}
return Output;
Enjoy!
Powered by: newtelligence dasBlog 2.3.9074.18820
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2012, © Copyright 2010
E-mail