Important alert: (current site time 5/25/2013 11:53:47 AM EDT) Brand new: recommended reading for every programming language on the site | revamped discussion board | 7 Source Code CDs

# Roman Numeral Converting Formatting Function

Email
 Submitted on: 7/2/2007 2:04:59 PM By: Soren Winslow Level: Beginner User Rating: By 1 Users Compatibility: ASP (Active Server Pages), HTML, VbScript (browser/client side) Views: 8557

This is a function that will convert a number into Roman numerals. It takes a look at each place value then converts it into the appropriate roman mumeral value. This function also includes proper formatting of values of 4,999 up to 3,999,999,999.

 Terms of Agreement:    By using this article, you agree to the following terms...    You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.    You may link to this article from another website, but ONLY if it is not wrapped in a frame.  You will abide by any additional copyright restrictions which the author may have placed in the article or article's description. ``` Roman Numeral Converting Formatting Function This is a function that will convert a number into Roman numerals. It takes a look at each place value then converts it into the appropriate roman mumeral value. This function also includes proper formatting of values of 4,999 up to 3,999,999,999. Roman numerals only consist of I, V, X, L, C, D and M. A line over a letter value means that base value times 1000. A double line over a letter value means that base value times 100,000. Here are the place values of roman numerals. I = 1 V = 5 X = 10 L = 50 C = 100 D = 500 M = 1,000 V = 5,000 X = 10,000 L = 50,000 C = 100,000 D = 500,000 M = 1,000,000 V = 5,000,000 X = 10,000,000 L = 50,000,000 C = 100,000,000 D = 500,000,000 M = 1,000,000,000 Here is the ASP code for this script:
"> Input a number:
<% TheNum = Request("TheNum") RomNum = "" Function RomanNumeral(TheNum) TheNum = CDbl(TheNum) SLine = "" DLine = "" R1 = "|I|II|III|IV|V|VI|VII|VIII|IX" R10 = "|X|XX|XXX|XL|L|LX|LXX|LXXX|XC" R100 = "|C|CC|CCC|CD|D|DC|DCC|DCCC|CM" R1K = "|" & _ "M|" & _ "MM|" & _ "MMM|" & _ "M" & SLine & "V|" & _ SLine & "V|" & _ SLine & "VM|" & _ SLine & "VMM|" & _ SLine & "VMMM|" & _ "M" & SLine & "X" R10K = "|" & _ SLine & "X|" & _ SLine & "XX|" & _ SLine & "XXX|" & _ SLine & "XL|" & _ SLine & "L|" & _ SLine & "LX|" & _ SLine & "LXX|" & _ SLine & "LXXX|" & _ SLine & "XC" R100K = "|" & _ SLine & "C|" & _ SLine & "CC|" & _ SLine & "CCC|" & _ SLine & "CD|" & _ SLine & "D|" & _ SLine & "DC|" & _ SLine & "DCC|" & _ SLine & "DCCC|" & _ SLine & "CM" R1M = "|" & _ SLine & "M|" & _ SLine & "MM|" & _ SLine & "MMM|" & _ SLine & "M" & DLine & "V|" & _ DLine & "V|" & _ DLine & "V" & SLine & "M|" & _ DLine & "V" & SLine & "MM|" & _ DLine & "V" & SLine & "MMM|" & _ DLine & "X" & SLine & "M" R10M = "|" & _ DLine & "X|" & _ DLine & "XX|" & _ DLine & "XXX|" & _ DLine & "XL|" & _ DLine & "L|" & _ DLine & "LX|" & _ DLine & "LXX|" & _ DLine & "LXXX|" & _ DLine & "XC" R100M = "|" & _ DLine & "C|" & _ DLine & "CC|" & _ DLine & "CCC|" & _ DLine & "CD|" & _ DLine & "D|" & _ DLine & "DC|" & _ DLine & "DCC|" & _ DLine & "DCCC|" & _ DLine & "CM" R1B = DLine & "M" PlaceVals = Array(R1,R10,R100,R1K,R10K,R100K,R1M,R10M,R100M) For x = 1 To Len(TheNum) IntNum = Cint(Mid(TheNum,Len(TheNum)-(x-1),1)) If x < 10 Then RNumArr = Split(PlaceVals(x-1),"|") RomNum = RNumArr(IntNum) & RomNum Else For y = 1 to IntNum RomNum = R1B & RomNum Next End If Next RomanNumeral = RomNum End Function If Len(Trim(TheNum)) > 0 Then If IsNumeric(TheNum) = False Then Response.Write "Please enter a number" Else Response.Write FormatNumber(TheNum,0) & " = " & RomanNumeral(TheNum) End If End If %>
```

Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)