pub struct Num2Words { /* private fields */ }
Expand description

Builder for num2words

Implementations

Creates a new builder

Example:

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

Sets the language of the output

For all of the available languages, see Lang.

Example:

use num2words::{Num2Words, Lang};
assert_eq!(
    Num2Words::new(42).lang(Lang::English).to_words(),
    Ok(String::from("forty-two"))
);

Sets the type of output to cardinal (forty-two)

Example:

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

Sets the type of output to ordinal (forty-second)

Example:

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

Sets the type of output to numbered ordinal (42nd)

Example:

use num2words::Num2Words;
assert_eq!(
    Num2Words::new(42).ordinal_num().to_words(),
    Ok(String::from("42nd"))
);

Sets the type of output to year (nineteen oh-one)

Example:

use num2words::Num2Words;
assert_eq!(
    Num2Words::new(1901).year().to_words(),
    Ok(String::from("nineteen oh-one"))
);

Sets the output to the currency it has been given

For all of the available currencies, see Currency.

Example:

use num2words::{Num2Words, Currency};
assert_eq!(
    Num2Words::new(42.01).currency(Currency::DOLLAR).to_words(),
    Ok(String::from("forty-two dollars and one cent"))
);

Builds the output

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.