Roman Numerals Converter << Back



To convert a number to Roman numerals format.

SymbolValue
I1
V5
X10
L50
C100
D500
M1,000
 
SymbolValue
I1,000
V5,000
X10,000
L50,000
C100,000
D500,000
M1,000,000

Use UI

Define ROMANDIGITSCONST For "IVXLCDM"

Function RomanDigits Global Returns String[]
	Integer iLength iIndex
	String[] sArray
	Move (Length(ROMANDIGITSCONST)) to iLength
	For iIndex From 1 to iLength
		Move (Mid(ROMANDIGITSCONST,1,iIndex)) to sArray[iIndex - 1]
	Loop
	For iIndex From 2 to iLength
		#IF !@<200
			Move ("_"+Mid(ROMANDIGITSCONST,2,iIndex)) to sArray[iLength + iIndex - 2]
		#ELSE
			Move (Mid(ROMANDIGITSCONST,2,iIndex) + Character(773)) to sArray[iLength + iIndex - 2]
		#ENDIF
	Loop
	Function_Return sArray
End_Function // RomanDigits

Function RomanNumeral Global Integer iNum Returns String
	Integer iDigit iIndex
	String sResult sRomanDigit sOne sFive
	String[] sRomanDigits
	Move "" to sResult
	If (iNum>0 And iNum<4000000) Begin
		Move 0 to iIndex
		Move (RomanDigits()) to sRomanDigits
		While (iNum > 0)
			Move sRomanDigits[iIndex] to sOne
			Move sRomanDigits[iIndex + 1] to sFive
			Move (Mod(iNum, 10)) to iDigit
			Move (iNum / 10) to iNum
			If (iDigit) Begin
				If (iDigit >= 1 And iDigit <= 3) Move (Repeat(sOne, iDigit)) to sRomanDigit
				Else If (iDigit = 4) Move (sOne + sFive) to sRomanDigit
				Else If (iDigit = 5) Move sFive to sRomanDigit
				Else If (iDigit >= 6 And iDigit <=8) Move (sFive + Repeat(sOne, iDigit - 5)) to sRomanDigit
				Else If (iDigit = 9) Move (sOne + sRomanDigits[iIndex + 2]) to sRomanDigit
				Move (sRomanDigit + sResult) to sResult
			End
			Add 2 to iIndex
		Loop
	End
	Function_Return sResult
End_Function // RomanNumeral

In DF 20, we can take advantage of Unicode support by using the overline combined character. In the Roman Numerals world, you can add an overline character to the existing unit to make it 1000 times.






Free Web Hosting