A Rust trait to convert numbers of any type and size to their English representation.
MIT License
This Rust crate provides the NumberToEnglish
trait which can be used to convert any* number to its string representation in English.
It uses the Conway-Wechsler system for converting numbers to words. Other systems might be added in the future.
Add this to your Cargo.toml:
[dependencies]
num2english = { git = "https://github.com/trvswgnr/num2english", branch = "main" }
Then add this to your crate root:
use num2english::NumberToEnglish;
use num2english::NumberToEnglish;
assert_eq!(6.000_052.to_english(), "six and fifty-two millionths");
assert_eq!(52.000_001.to_english(), "fifty-two and one millionth");
This will work even for incredibly large numbers:
assert_eq!(
f64::MAX.to_english(),
"one hundred seventy-nine uncentillion seven hundred sixty-nine centillion three hundred thirteen novenonagintillion four hundred eighty-six octononagintillion two hundred thirty-one septenonagintillion five hundred seventy senonagintillion"
);
Numbers that use scientific notation when represented as a string are not supported. This means that BigFloat
is not supported yet, but BigInt
is.
This project is licensed under the MIT license. See LICENSE for more details.
Contributions are welcome! Please open an issue or submit a pull request.