Mega Code Archive
Converting a numeric value to roman notation (for beginners)
Title: Converting a numeric value to roman notation (for beginners)
Question: How to convert a numeric value to roman notation...
Answer:
// convert's decimal number to roman notation
function DecToRoman(intDecimal: longint): string;
const
arrRomans: array [1..13] of String = ('I', 'IV', 'V', 'IX', 'X', 'XL', 'L', 'XC', 'C', 'CD', 'D', 'CM', 'M');
arrArabics: array [1..13] of Integer = (1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000);
var
i: integer;
begin
// initialize the result
result := '';
for i := 13 downto 1 do
while (intDecimal = arrArabics[i]) do begin
intDecimal := intDecimal - arrArabics[i];
Result := Result + arrRomans[i];
end;
end;