Roman Numerals Converter
<< Back
To convert a number to
Roman numerals format.
Symbol | Value |
I | 1 |
V | 5 |
X | 10 |
L | 50 |
C | 100 |
D | 500 |
M | 1,000 |
Symbol | Value |
I | 1,000 |
V | 5,000 |
X | 10,000 |
L | 50,000 |
C | 100,000 |
D | 500,000 |
M | 1,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.