Roman
Parses or formats Roman numerals.
Syntax
-
Roman(n)
-
n
is an integer
-
-
Roman(s)
-
s
is a string
-
Description
If n
is an integer, then Roman(n)
returns n
formatted as a Roman numeral.
If s
is a string containing a Roman numeral representation of an integer, then Roman(s)
returns this integer; that is, Roman(s)
parses s
as a Roman numeral.
If n
is an integer, Roman(n)
is equivalent to SetFormatStyle(n, "Roman")
.
Examples
Roman(1987)
MCMLXXXVII
Roman("MCMLXXXVII")
1987
Notes
The integer 0
is formatted as N
in Roman numerals:
Roman(0)
N
Roman("N")
0
Negative values are prefixed with a minus sign in Roman numerals:
Roman(−520)
−DXX
However, the minus sign is not allowed when parsing strings as Roman numerals.
In Roman numerals, large numbers are written in groups separated by hyphens. Read from right to left, each hyphen signals an additional factor of one thousand:
Roman(299792458)
CCXCIX'DCCXC'MMCDLVIII
This should be parsed as
MMCDLVIII + 10³⋅DCCXC + 10⁶⋅CCXCIX
And, indeed,
Roman("CCXCIX'DCCXC'MMCDLVIII")
299792458
The parser is forgiving and accepts non-standard Roman numerals, as long as they are unambiguous. For example,
'( "MCMLXXXVII", "LMMXXXVII", "XXMMVII", "XXMMIIIIIII", 1987⋅"I" ) @ Roman
1987 1987 1987 1987 1987
where the last string in the list literally consists of the character I
repeated 1987 times.