num2words

Convert number like 42 to forty-two

Usage

This crate can be either used as a library or a binary.

Library

Example usage:

rust use num2words::Num2Words; assert_eq!(Num2Words::new(42).to_words(), Ok(String::from("forty-two")));

The builder Num2Words can take any of these arguments: lang, cardinal, ordinal, ordinal_num, year, and currency.

rust use num2words::*; assert_eq!( Num2Words::new(42).lang(Lang::English).to_words(), Ok(String::from("forty-two")) ); assert_eq!( Num2Words::new(42).ordinal().to_words(), Ok(String::from("forty-second")) ); assert_eq!( Num2Words::new(42.01).currency(Currency::DOLLAR).to_words(), Ok(String::from("forty-two dollars and one cent")) );

These arguments can be chained.

For more information about the available languages, outputs and currencies, see Information.

Binary

This crate provides a command-line interface to run requests on num2words.

Example: sh $ num2words 42 forty-two $ num2words 10 --to EUR ten euros

You can download the app via the following command: sh $ cargo install num2words

You can also change the language via the argument --lang and provide an output or a currency with the argument --to.

For more information about the usage of num2words please refer to the docs or via the following command: sh $ num2words --help

Information

Supported languages

Here is a list of all of the supported languages:

| Flag | Code | CLI code | Language | 42 | | ---- | --------------- | --------------- | -------- | --------- | | πŸ‡ΊπŸ‡ΈπŸ‡¬πŸ‡§ | Lang::English | en | English | forty-two |

This list can be expanded! Contributions are welcomed.

Supported output

Here is a list of all of the supported outputs (with the command-line interface code):

Supported currencies

Here is a list of all of the supported currencies (with the command-line interface code):

About

This library is widely inspired by Savoir-faire Linux's Python lib.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.