# Roman Numeral Converter Extension

Couldn’t find a way to convert a number to roman numerals, so I wrote a quick extension. Here people go.

[spoiler][code]Roman Numerals by William S Martin begins here.

To say (N - a number) as roman numerals:
let the numeral be an indexed text;
let X be N divided by 1000;
let Y be the remainder after dividing N by 1000;
let Z be the remainder after dividing N by 100;
let W be the remainder after dividing N by 10;
if X is greater than 0:
repeat with temp1 running from 1 to X:
now the numeral is “[numeral]M”;
if Y is greater than 99:
let C be Y divided by 100;
if C is:
– 1: now the numeral is “[numeral]C”;
– 2: now the numeral is “[numeral]CC”;
– 3: now the numeral is “[numeral]CCC”;
– 4: now the numeral is “[numeral]CD”;
– 5: now the numeral is “[numeral]D”;
– 6: now the numeral is “[numeral]DC”;
– 7: now the numeral is “[numeral]DCC”;
– 8: now the numeral is “[numeral]DCCC”;
– 9: now the numeral is “[numeral]CM”;
– otherwise: now the numeral is “[numeral]{hundreds place error}”;
if Z is greater than 9:
let D be Z divided by 10;
if D is:
– 1: now the numeral is “[numeral]X”;
– 2: now the numeral is “[numeral]XX”;
– 3: now the numeral is “[numeral]XXX”;
– 4: now the numeral is “[numeral]XL”;
– 5: now the numeral is “[numeral]L”;
– 6: now the numeral is “[numeral]LX”;
– 7: now the numeral is “[numeral]LXX”;
– 8: now the numeral is “[numeral]LXXX”;
– 9: now the numeral is “[numeral]XC”;
– otherwise: now the numeral is “[numeral]{tens place error}”;
if W is greater than 0:
if W is:
– 1: now the numeral is “[numeral]I”;
– 2: now the numeral is “[numeral]II”;
– 3: now the numeral is “[numeral]III”;
– 4: now the numeral is “[numeral]IV”;
– 5: now the numeral is “[numeral]V”;
– 6: now the numeral is “[numeral]VI”;
– 7: now the numeral is “[numeral]VII”;
– 8: now the numeral is “[numeral]VIII”;
– 9: now the numeral is “[numeral]IX”;
– otherwise: now the numeral is “[numeral]{ones place error}”;
say the numeral.

Roman Numerals ends here.

---- DOCUMENTATION ----

An extremely simple extension. Convert a number to a roman numeral. Doesn’t work on positive numbers, or at least it shouldn’t.

To convert a number, simply use the phrase “[A number] as roman numerals”

Example: * Romanize the Numbers! - An easy way to test the features of this extension.

*: “Romanize the Numbers”

``````Include Roman Numerals by William S Martin.

The Roman forum is a room. "This forum exists for a specific purpose: to convert unworthy arabic numbers to virtuous Roman ones. To begin the arduous task of converting the numbers of the universe, shout 'romanize' and then the number you wish to change."

Romanizing is an action applying to one number.
Understand "romanize [a number]" as romanizing.

Check romanizing:
if the number understood is less than 1:
say "Zero and negative numbers haven't been invented yet!" instead.

Carry out romanizing:
say "[the number understood as roman numerals]".[/code][/spoiler]``````

I assume you want “Only works on positive numbers” or “Doesn’t work on negative numbers or zero”.

-Kevin

The Romans had no way of writing zero. Zero was an invention of the Arabs.

Nice work! You might want to make a few minor changes though if you’re thinking of submitting it the extensions website.

You might want to consider using this.

``To say (N - a number) as/in roman --/numerals/numbers:``

This is so that alternative phrasing like “[N in roman numbers]” works.

Hope this helps.

No, it’s from India. The Arabs were the ones to convey it to Europe, though.

D’oh!

Yes, if I get around to submitting it, I’ll definitely use those. Thanks.

Yes, I should stipulate that too.

Wow! Very neat.

Eyeballing stress cases–what do you plan to do for a numeral above 10000? I know they generally put a bar above the numeral, but that’s not practical–perhaps you should have a fallback instead? Or reject the reader’s attempts to choose a number over a certain amount? That’s what online converters seem to do, and it seems like fair play.

MMMMMMMMMMMMXIV is a bit messy & that’s what the code seems to do eyeballing it.

Also, I don’t know how to make an example, but it’d be neat to have examples of the trickiest test cases.

Another request, if you decide to publish it on the extension site:

``` To say (N - number) as small roman numerals: ```yielding i, ii, iii, iv, v, vi, etc.(rather than I, II, III, IV …).

You can do that like this.

``To say (N - number) as small roman numerals: say "[N as roman numerals]" in lower case.``

Hope this helps.

I’m not exactly sure there is a thing like a lowercase roman numeral. I think it’s an invention made by Microsoft for bulletting text in MSWord. Ofc, this is just an assumption and I may be completely wrong.

Lowercase roman numerals are commonly used for page numbering, mostly in things like prefaces. (The body text of the book is given page numbers starting with 1; the preface, acknowledgements, publishing information, etc. gets lowercase Roman numerals.)

Also, back in the olden days, when people actually used roman numerals in print and writing, roman numerals were mostly in lower case (the unicode name for them is “small roman numerals”).

As regards values over 10,000: One convention I’ve seen - but have never seen a formal statement of - is to divide by 1,000 and postpend an apostrophe, so 32,768 would be XXX’MMDCCLXVIII

Since there’s a lot of unexpected interest, I’ve decided to write a version to be published to the I7 site, incorporating some of the feedback on this thread. If you contributed something and don’t wish to be credited, please let me know.

My cursory research revealed that medieval mathematicians added additional symbols going up to a hundred thousand, but these were weird symbols that involved overlined V’s and I’s or reverse C’s. It’s certainly possible, I might add a “medieval numbers” function, but if I want it to be historical I’m rather stuck on this system. I don’t particularly want to hardcode a limit either, but I’ll probably give a warning to authors and recommend they limit it to numbers under 10,000.

Seems simple enough. I’ll add it.

I still believe those were made 1,500 years after the decay of the Roman Empire. I think they didn’t even have lower case LETTERS, back then. The wrote everything in CAPS LIKE A CAPSLOCKED ANGRY TEENAGER.

Also, the letter U was not there and they used the V.
Like in VNICVM. IMPERIVS. VRBI ET ORBI. ET CETERA.

More assumptions

Oh, you mean back in what was the good old days of yore even back in the gold old days! Yes, I think we can pretty safely assume that the ancient Romans were seriously prejudiced against lower case letters generally – the ancienter, the seriouslier.

It’s more likely that the concept of upper case and lower case didn’t exist back then.

It didn’t. And when it was invented in the fifth century, they called them minuscule and majuscules. Upper and lower case was only used with the printing press, when you’d have two cases of letters to choose from.
They also often didn’t write with spaces!
Also also sometimes they wrote in Boustrophedon style!

Here is the final version that I’ll submit to the site:

[spoiler][code]Version 1/121107 of Roman Numerals by William S Martin begins here.

To say (N - a number) as/in roman numerals/numbers:
if N is greater than 32767:
say “{Roman Numerals extension failed: number too large}”;
else:
let the numeral be an indexed text;
let X be N divided by 1000;
let Y be the remainder after dividing N by 1000;
let Z be the remainder after dividing N by 100;
let W be the remainder after dividing N by 10;
if X is greater than 0:
repeat with temp1 running from 1 to X:
now the numeral is “[numeral]M”;
if Y is greater than 99:
let C be Y divided by 100;
if C is:
– 1: now the numeral is “[numeral]C”;
– 2: now the numeral is “[numeral]CC”;
– 3: now the numeral is “[numeral]CCC”;
– 4: now the numeral is “[numeral]CD”;
– 5: now the numeral is “[numeral]D”;
– 6: now the numeral is “[numeral]DC”;
– 7: now the numeral is “[numeral]DCC”;
– 8: now the numeral is “[numeral]DCCC”;
– 9: now the numeral is “[numeral]CM”;
– otherwise: now the numeral is “[numeral]{hundreds place error}”;
if Z is greater than 9:
let D be Z divided by 10;
if D is:
– 1: now the numeral is “[numeral]X”;
– 2: now the numeral is “[numeral]XX”;
– 3: now the numeral is “[numeral]XXX”;
– 4: now the numeral is “[numeral]XL”;
– 5: now the numeral is “[numeral]L”;
– 6: now the numeral is “[numeral]LX”;
– 7: now the numeral is “[numeral]LXX”;
– 8: now the numeral is “[numeral]LXXX”;
– 9: now the numeral is “[numeral]XC”;
– otherwise: now the numeral is “[numeral]{tens place error}”;
if W is greater than 0:
if W is:
– 1: now the numeral is “[numeral]I”;
– 2: now the numeral is “[numeral]II”;
– 3: now the numeral is “[numeral]III”;
– 4: now the numeral is “[numeral]IV”;
– 5: now the numeral is “[numeral]V”;
– 6: now the numeral is “[numeral]VI”;
– 7: now the numeral is “[numeral]VII”;
– 8: now the numeral is “[numeral]VIII”;
– 9: now the numeral is “[numeral]IX”;
– otherwise: now the numeral is “[numeral]{ones place error}”;
say the numeral.

To say (N - a number) as/in small roman numerals/numbers: say “[N as roman numerals]” in lower case.

Roman Numerals ends here.

---- DOCUMENTATION ----

An extremely simple extension. Convert a number to a roman numeral. Doesn’t work on negative numbers or numbers, or at least it shouldn’t.

Try not use number over 10,000, they will look odd and process slowly. Really big numbers might break the system, so there is a limit on numbers as large as 32,767 (which happens to be the upper limit of non-glulx, Inform, funny that).

To convert a number, simply use the phrase “[A number] as roman numerals”. You can also use “[A number] as small roman numerals” to have them printed as “i”,“vi”, “mmxci” etc.

A quick thanks to jacksonmead, climbingstars, Ned Yompas and Felix Larsson from the Intfiction.org forum who provided feedback that was incorporated into the final version of this extension.

Example: * Romanize the Numbers! - An easy way to test the features of this extension.

*: “Romanize the Numbers”

``````Include Roman Numerals by William S Martin.

The Roman forum is a room. "This forum exists for a specific purpose: to convert unworthy arabic numbers to virtuous Roman ones. To begin the arduous task of converting the numbers of the universe, shout 'romanize' and then the number you wish to change. Shout 'small romanize' in case you want delightful lower case roman numerals."

Romanizing is an action applying to one number.
Understand "romanize [a number]" as romanizing.

Check romanizing:
if the number understood is less than 1:
say "Zero and negative numbers haven't been invented yet!" instead.

Check romanizing:
if the number understood is greater than 10,000:
say "It's a mouthful to say more than X Ms."

Carry out romanizing:
say "[the number understood as roman numerals]".

Small romanizing is an action applying to one number.
Understand "small romanize [a number]" as small romanizing.

Check small romanizing:
if the number understood is less than 1:
say "Zero and negative numbers haven't been invented yet!" instead.

Check small romanizing:
if the number understood is greater than 10,000:
say "It's a mouthful to say more than X Ms."

Carry out small romanizing:
say "[the number understood as small roman numerals]".
``````

[/code][/spoiler]

I did eventually add a hardcoded limit to the size of the numbers, because it is easy to slip and add an extra “0”, which might be fairly disastrous.

Nice work! By the way it’s “Ned Yompus” not “Ned Yompas”.