decimal to roman numerals conversion
Is it possible to make this kinda program using IF STATEMENTS only? or FOR NEXT statements??
Need your help guys!!! :confused:
# 1 Re: decimal to roman numerals conversion
I got this function over the net. Just pass in the numeric value and it will return you the equivalent Roman number.
' Formats a number as a roman numeral.
' Author: Christian d'Heureuse (www.source-code.biz)
Public Function FormatRoman(ByVal n As Integer) As String
If n = 0 Then FormatRoman = "0": Exit Function
' There is no roman symbol for 0, but we don't want to return an empty string.
Const r = "IVXLCDM" ' roman symbols
Dim i As Integer: i = Abs(n)
Dim s As String, p As Integer
For p = 1 To 5 Step 2
Dim d As Integer: d = i Mod 10: i = i \ 10
Select Case d ' format a decimal digit
Case 0 To 3: s = String(d, Mid(r, p, 1)) & s
Case 4: s = Mid(r, p, 2) & s
Case 5 To 8: s = Mid(r, p + 1, 1) & String(d - 5, Mid(r, p, 1)) & s
Case 9: s = Mid(r, p, 1) & Mid(r, p + 2, 1) & s
End Select
Next
s = String(i, "M") & s ' format thousands
If n < 0 Then s = "-" & s ' insert sign if negative (non-standard)
FormatRoman = s
End Function