Convert Numbers To Roman Numerals – Romanice

Category: Javascript | January 11, 2021
Author:dkin-om
Views Total:549 views
Official Page:Go to website
Last Update:January 11, 2021
License:MIT

Preview:

Convert Numbers To Roman Numerals – Romanice

Description:

Romanice is a dependency-free JavaScript library that converts Arabic numbers (1, 2, 3, …) to roman numerals (I, II, III, …) and vice versa.

How to use it:

1. Install and import the Romanice as an ES module.

# NPM
$ npm i romanice
import * as Romanice from 'romanice';

2. Or load the compiled JavaScript file in the document.

// From Local
<script src="./dist/romanice.min.js"></script>
// From A CDN
<script src="https://cdn.jsdelivr.net/npm/romanice/dist/romanice.min.js"></script>

3. Create a standard Roman Numeral converter.

const { romanice } = Romanice;
const standardConverter = romanice();

4. Convert Arabic numbers to roman numerals.

const roman = standardConverter.toRoman(1234);
=> MCCXXXIV

5. Convert roman numbers to Arabic numerals.

const decimal = standardConverter.fromRoman('MCCXXXIV');
=> 1234

6. Customize the Roman numeral symbols.

const { romanice, symbols } = Romanice;
const unicodeConverter = romanice(symbols.UNICODE);
const roman = unicodeConverter.toRoman(123456);
=> ↂↀↀⅭⅭⅭⅩⅬⅤ
const decimal = unicodeConverter.fromRoman('ↂↀↀⅭⅭⅭⅩⅬⅤ');
=> 123456

You Might Be Interested In:


Leave a Reply