# Use Roman Numerals

You can easily convert standard Arabic numbers to Roman numerals using HotDocs. For example, if you already have a Number variable and you want to display it as a Roman numeral, use the IX or ix format:

```  FORMAT( Num Var, "IX" )
```

Converting from Roman numerals to Arabic numbers is much more difficult, however. You must use a computation that can translate each letter to its corresponding value, then add or subtract these values as needed.

To better understand the following computation, note the values for each of the Roman numerals:

Letter Value
M 1000
C 500
L 100
D 50
X 10
V 5
I 1

Roman numerals are converted from left to right by adding the value for each letter in the number. If a letter with a higher value comes after a letter with a lower value, the lower value is subtracted from the total instead of added. For example, in the number XIV, since I has a lower value than V, it is subtracted. Thus, to convert XIV to an Arabic number, the calculation is 10 - 1 + 5 = 14.

 CAUTION: This computation uses the WHILE and INCREMENT instructions, which work only in HotDocs 6.2 and higher.

## Example

```0
SET Num Var TO 1

WHILE Num Var <= LENGTH( Text Var )
IF MID( Text Var, Num Var, 1 ) = "M"
RESULT + 1000
ELSE IF MID( Text Var, Num Var, 1 ) = "D"
IF Num Var < LENGTH( Text Var ) AND "M" CONTAINS MID( Text Var, Num Var + 1, 1 )
RESULT - 500
ELSE
RESULT + 500
END IF
ELSE IF MID( Text Var, Num Var, 1 ) = "C"
IF Num Var < LENGTH( Text Var ) AND "MD" CONTAINS MID( Text Var, Num Var + 1, 1 )
RESULT - 100
ELSE
RESULT + 100
END IF
ELSE IF MID( Text Var, Num Var, 1 ) = "L"
IF Num Var < LENGTH( Text Var ) AND "MDC" CONTAINS MID( Text Var, Num Var + 1, 1 )
RESULT - 50
ELSE
RESULT + 50
END IF
ELSE IF MID( Text Var, Num Var, 1 ) = "X"
IF Num Var < LENGTH( Text Var ) AND "MDCL" CONTAINS MID( Text Var, Num Var + 1, 1 )
RESULT - 10
ELSE
RESULT + 10
END IF
ELSE IF MID( Text Var, Num Var, 1 ) = "V"
IF Num Var < LENGTH( Text Var ) AND "MDCLX" CONTAINS MID( Text Var, Num Var + 1, 1 )
RESULT - 5
ELSE
RESULT + 5
END IF
ELSE IF MID( Text Var, Num Var, 1 ) = "I"
IF Num Var < LENGTH( Text Var ) AND "MDCLXV" CONTAINS MID( Text Var, Num Var + 1, 1 )
RESULT - 1
ELSE
RESULT + 1
END IF
END IF
INCREMENT Num Var
END WHILE```

 Text Var A Text variable containing a Roman numeral. Num Var A temporary Number variable used in the computation. (See Create a Temporary Variable.)