首页  编辑  

十进制转换为罗马数字

Tags: /超级猛料/String.字符串处理/   Date Created:

function DecToRoman ( iDecimal: longint ): string;

const

    aRomans: array [ 1..13 ] of string = ( 'I', 'IV', 'V', 'IX', 'X', 'XL', 'L', 'XC', 'C', 'CD', 'D', 'CM', 'M' );

    aArabics: array [ 1..13 ] of integer = ( 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000 );

var

  i: integer;

begin

    result := '';

    for i := 13 downto 1 do

        while ( iDecimal >= aArabics [ i ] ) do begin

              iDecimal := iDecimal - aArabics [ i ];

              result := result + aRomans [ i ];

        end;

end;