Author: Jonas Bilinkevicius
How to convert an integer value to a Roman Numeral representation
Answer:
Converts an integer value to a string containing a roman numeric code ("XVII"):
1
2 {Parameters: - Num: Integer to convert.
3 Return Value: - Roman numerical representation of the passed integer value.
4 History: 12/7/99 "Philippe Ranger" (PhilippeRanger@compuserve.com)}
5
6 function IntToRoman(num: Cardinal): string; {returns num in capital roman digits}
7 const
8 Nvals = 13;
9 vals: array[1..Nvals] of word = (1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900,
10 1000);
11 roms: array[1..Nvals] of string[2] = ('I', 'IV', 'V', 'IX', 'X', 'XL', 'L', 'XC',
12 'C', 'CD', 'D', 'CM', 'M');
13 var
14 b: 1..Nvals;
15 begin
16 result := '';
17 b := Nvals;
18 while num > 0 do
19 begin
20 while vals[b] > num do
21 dec(b);
22 dec(num, vals[b]);
23 result := result + roms[b]
24 end;
25 end;
|