Skip to content

Repository files navigation

Numeri Romani

A modern .NET library for converting and validating Roman numerals in your applications.

Installation

Install Numeri Romani using the NuGet Package Manager.

Restrictions

The library currently supports integers in the range from 0 to 499,999.

Features

Format Integers as Roman Numerals

Option 1: Extension method for int

Use the ToRoman() extension method to easily convert an integer to its Roman numeral representation:

using LinkeEngineering.NumeriRomani;

int number = 123;

string roman = number.ToRoman();
// assigns "CXXIII"

Option 2: Using RomanNumeralsFormatter

For advanced formatting, use the RomanNumeralsFormatter with String.Format(). Supported format strings are: empty, "g", "G", or "R".

using LinkeEngineering.NumeriRomani;

int number = 123;

RomanNumeralsFormatter formatter = new();
string roman = String.Format(formatter, "{0:R}", number);
// assigns "CXXIII"

Parse Roman Numerals to Integers

Option 1: Parsing With ParseRoman()

Use the extensions method ParseRoman() to convert a Roman numeral string to its integer value:

using LinkeEngineering.NumeriRomani;

string roman = "CXXIII";

int number1 = roman.ParseRoman()
// assigns 123

Option 2: Safe Parsing With TryParseRoman()

Use the extension method TryParseRoman() to safely parse a Roman numeral string to its integer value:

using LinkeEngineering.NumeriRomani;

string roman = "CXXIII";

bool isSuccess = roman.TryParseRoman(out int number);
// returns true and assigns 123 to number

License

This library is licensed under the MIT License, with additional terms restricting the use of the original package name for modified versions. Please refer to the license file for details.

About

A .NET library for dealing with Roman numerals.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages