pub fn to_word(x: u64, and_behavior: AndBehavior) -> String
Expand description

Convert a 64-bit unsigned integer to words

Examples

use numbers_into_words::{to_word, AndBehavior};

// US population according to 2020 census
// https://www2.census.gov/library/publications/decennial/2020/census-briefs/c2020br-01.pdf

assert_eq!(
    to_word(330_759_736, AndBehavior::All),
    String::from(
        "three-hundred and thirty million, \
        seven-hundred and fifty-nine thousand, \
        seven-hundred and thirty-six"
    )
);
assert_eq!(
    to_word(330_759_736, AndBehavior::LastGroup),
    String::from(
        "three-hundred thirty million, \
        seven-hundred fifty-nine thousand, \
        seven-hundred and thirty-six"
    )
);

assert_eq!(
    to_word(330_759_736, AndBehavior::OnlyUnderThousand),
    String::from(
        "three-hundred thirty million, \
        seven-hundred fifty-nine thousand, \
        seven-hundred thirty-six"
    )
);

assert_eq!(
    to_word(123, AndBehavior::OnlyUnderThousand),
    String::from("one-hundred and twenty-three")
);

assert_eq!(
    to_word(123, AndBehavior::None),
    String::from("one-hundred twenty-three")
);

assert_eq!(to_word(0, AndBehavior::None), "zero".to_string());