Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to convert an integer value to a Roman Numeral representation Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
19-Oct-02
Category
Algorithm
Language
Delphi 2.x
Views
98
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			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;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC