34 lines
913 B
C#
34 lines
913 B
C#
namespace Volian.Controls.Library
|
|
{
|
|
public static class RomanNumeral
|
|
{
|
|
private enum RomanOffset : int
|
|
{
|
|
Hundreds = 2,
|
|
Tens = 4,
|
|
Units = 6
|
|
}
|
|
private static readonly string _Romans = "MDCLXVI";
|
|
private static string RomanPart(RomanOffset offset, int value)
|
|
{
|
|
int iFive = value / 5;
|
|
int iUnits = value % 5;
|
|
int iFour = iUnits / 4;
|
|
return _Romans.Substring(((int)offset), iFour) +
|
|
_Romans.Substring(((int)offset) - iFive - iFour, iFive | iFour) +
|
|
"".PadRight(iUnits % 4, _Romans[((int)offset)]);
|
|
}
|
|
public static string Convert(int number)
|
|
{
|
|
int thousands = number / 1000;
|
|
int hundreds = (number % 1000) / 100;
|
|
int tens = (number % 100) / 10;
|
|
int units = number % 10;
|
|
return "".PadRight(thousands, _Romans[0]) +
|
|
RomanPart(RomanOffset.Hundreds, hundreds) +
|
|
RomanPart(RomanOffset.Tens, tens) +
|
|
RomanPart(RomanOffset.Units, units);
|
|
}
|
|
}
|
|
}
|