Skip to content

Library that can convert numbers in our Base 10 Arabic Numeral System to the Roman Numeral System, and vice versa, in Rust.

License

Notifications You must be signed in to change notification settings

ferdinandkeller/roman-numerals-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Roman Numerals

This library can help you convert numbers in our Base 10 Arabic Numeral System to Roman Numeral System, and vice versa.

Using this library you can parse arbitrarily large numbers, including in the thousands, millions, billions, and above, as long as they fit into the u128 type or smaller.

It is compatible with all unsigned integer types, from u8 to u128, including usize.

Installation

Add roman_numerals to your Cargo.toml, or run the following command:

cargo add roman-numerals

The library is available on crates.io.

Usage

Convert to Roman

use roman_numerals::ToRoman;

assert_eq!(1u32.to_roman(), "I");
assert_eq!(2u32.to_roman(), "II");
assert_eq!(3u32.to_roman(), "III");
assert_eq!(1_000_000u64.to_roman(), "M̄");

Parse Roman

use roman_numerals::FromRoman;

assert_eq!(u32::from_roman("ABC"), None);
assert_eq!(u32::from_roman("I"), Some(1));
assert_eq!(u32::from_roman("II"), Some(2));
assert_eq!(u32::from_roman("III"), Some(3));

Contributing

You can start a development environment instantly on this library by clicking this link. You need Docker Desktop installed and running on your machine for it to work.

About

Library that can convert numbers in our Base 10 Arabic Numeral System to the Roman Numeral System, and vice versa, in Rust.

Resources

License

Stars

Watchers

Forks

Languages