Soren Winslow Soren Winslow
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

Input a number:

Here is the ASP code for this script:



<div class="breg" style="text-align:left;padding-left:20px;">

<form name="GenRomNum" method="post" action="<%=Request.ServerVariables("URL")%>">

Input a number: <input type="text" name="TheNum" size="6">

<input type="submit" value="Convert">

</form>

</div>



<div class="breg" style="text-align:left;padding-left:20px;">

<%

 TheNum = Request("TheNum")

 RomNum = ""



 Function RomanNumeral(TheNum)

   If IsNumeric(TheNum) = False Then

      RomanNumeral = "<b>Please Enter a Number</b>"

   Else

     TheNum = Round(TheNum,0)

     SLine = "<span style=" & chr(34) & "text-decoration:overline;" & chr(34) & ">"

     DLine = "<span style=" & chr(34) & "border-top-style:double;" & chr(34) & ">"





    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</span>|" & _

          SLine & "V</span>|" & _

          SLine & "V</span>M|" & _

          SLine & "V</span>MM|" & _

          SLine & "V</span>MMM|" & _

          "M" & SLine & "X</span>"

    R10K = "|" & _

           SLine & "X</span>|" & _

           SLine & "XX</span>|" & _

           SLine & "XXX</span>|" & _

           SLine & "XL</span>|" & _

           SLine & "L</span>|" & _

           SLine & "LX</span>|" & _

           SLine & "LXX</span>|" & _

           SLine & "LXXX</span>|" & _

           SLine & "XC</span>"

    R100K = "|" & _

            SLine & "C</span>|" & _

            SLine & "CC</span>|" & _

            SLine & "CCC</span>|" & _

            SLine & "CD</span>|" & _

            SLine & "D</span>|" & _

            SLine & "DC</span>|" & _

            SLine & "DCC</span>|" & _

            SLine & "DCCC</span>|" & _

            SLine & "CM</span>"

    R1M = "|" & _

          SLine & "M</span>|" & _

          SLine & "MM</span>|" & _

          SLine & "MMM</span>|" & _

          SLine & "M</span>" & DLine & "V</span>|" & _

          DLine & "V</span>|" & _

          DLine & "V</span>" &  SLine & "M</span>|" & _

          DLine & "V</span>" &  SLine & "MM</span>|" & _

          DLine & "V</span>" &  SLine & "MMM</span>|" & _

          DLine & "X</span>" &  SLine & "M</span>"

    R10M = "|" & _

           DLine & "X</span>|" & _

           DLine & "XX</span>|" & _

           DLine & "XXX</span>|" & _

           DLine & "XL</span>|" & _

           DLine & "L</span>|" & _

           DLine & "LX</span>|" & _

           DLine & "LXX</span>|" & _

           DLine & "LXXX</span>|" & _

           DLine & "XC</span>"

    R100M = "|" & _

            DLine & "C</span>|" & _

            DLine & "CC</span>|" & _

            DLine & "CCC</span>|" & _

            DLine & "CD</span>|" & _

            DLine & "D</span>|" & _

            DLine & "DC</span>|" & _

            DLine & "DCC</span>|" & _

            DLine & "DCCC</span>|" & _

            DLine & "CM</span>"

    R1B = DLine & "M</span>"



     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 = TheNum & " = " & RomNum

   End If

 End Function



 If Len(Trim(TheNum)) > 0 Then

     Response.Write RomanNumeral(TheNum)

 End If





%>



</div>

               
© 1967 - 2017 Soren Winslow