A Rust trait to convert numbers of any type and size to their English representation.

Overview

num2english

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.

Usage

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;

Examples

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"
);

*Limitations

Numbers that use scientific notation when represented as a string are not supported. This means that BigFloat is not supported yet, but BigInt is.

License

This project is licensed under the MIT license. See LICENSE for more details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

You might also like...
Compare the size of v8 and quickjs
Compare the size of v8 and quickjs

rust_v8_and_quickjs Size debug release quickjs 1,758,728 1,281,104 v8 40,047,648 20,956,816 Chart License rust_v8_and_quickjs is released under the MI

🚀simple server that returns error codes with their respective messages and debug information, written in rust 🦀
🚀simple server that returns error codes with their respective messages and debug information, written in rust 🦀

ErrorServer 🚀 A simple & lightweight server that returns a HTML page of the error code with its respective message and debug information, written in

A simple library to get all pairs from any Dex and sync reserves.

pair_sync A simple library to get all pairs from any supported Dex and sync reserves. Crates.io Documentation in progress Filename: examples/sync-pair

Tool to convert variable and function names in C/C++ source code to snake_case

FixNameCase Tool to convert variable and function names in C/C++ source code to snake_case. Hidden files and files listed in .gitignore are untouched.

A simple and convenient way to bundle owned data with a borrowing type.

A simple and convenient way to bundle owned data with a borrowing type. The Problem One of the main selling points of Rust is its borrow checker, whic

An implementation of a predicative polymorphic language with bidirectional type inference and algebraic data types

Vinilla Lang Vanilla is a pure functional programming language based on System F, a classic but powerful type system. Merits Simple as it is, Vanilla

A statically-typed, interpreted programming language, with generics and type inference

Glide A programming language. Currently, this includes: Static typing Generics, with monomorphization Type inference on function calls func identityT

Convert character to binary using Rust.
Convert character to binary using Rust.

Character-to-Binary-Rust This is a simple operation that is used to convert character to binary using Rust. Installation and Requirements First instal

An expression based data notation, aimed at transpiling itself to any cascaded data notation.

Lala An expression oriented data notation, aimed at transpiling itself to any cascaded data notation. Lala is separated into three components: Nana, L

Owner
Travis A. Wagner
full stack developer, designer, digital marketer, music producer.
Travis A. Wagner
Free Rust 🦀 course in English 🇬🇧

Learn Rust ?? Free Rust ?? course in English ???? This course was inspired by Dcode Before starting to learn a programming language, you need to under

Skwal 10 Jul 5, 2022
Build database expression type checker and vectorized runtime executor in type-safe Rust

Typed Type Exercise in Rust Build database expression type checker and vectorized runtime executor in type-safe Rust. This project is highly inspired

Andy Lok 89 Dec 27, 2022
A special rope, designed to work with any data type that is not String

AnyRope AnyRope is an arbitrary data type rope for Rust, designed for similar operations that a rope would do, but targeted at data types that are not

ahoyiski 27 Mar 22, 2023
Type erased vector. All elements have the same type.

Type erased vector. All elements have the same type. Designed to be type-erased as far as possible - most of the operations does not know about concre

null 7 Dec 3, 2022
Print out some fibonacci numbers.

give-me-some-fibonacci A Rust library for some fibonacci. TL;DR: its just a joke. Usage To get started using give_me_some_fibonacci, just add this to

Leonardo Vieira 2 Mar 22, 2022
A bit-packed k-mer representation (and relevant utilities) for rust

K-mer class for rust The purpose of this repository is to build a simple library that exposes a bit-packed k-mer class for use in rust-based bioinform

COMBINE lab 41 Dec 15, 2022
Bril: A Compiler Intermediate Representation for Learning

Bril: A Compiler Intermediate Representation for Learning Bril (the Big Red Intermediate Language) is a compiler IR made for teaching CS 6120, a grad

Lesley Lai 0 Dec 5, 2022
CBOR: Concise Binary Object Representation

CBOR 0x(4+4)9 0x49 “The Concise Binary Object Representation (CBOR) is a data format whose design goals include the possibility of extremely small cod

quininer 37 Dec 27, 2022
This crate allows to generate a flat binary with the memory representation of an ELF.

flatelf Library This crate allows to generate a flat binary with the memory representation of an ELF. It also allows to generate a FLATELF with the fo

Roi Martin 3 Sep 29, 2022
Macro for fast implementing serialize methods in serde::Serializer trait

impl_serialize! This library provides a simple procedural macro for fast implementing serialize methods in serde::Serializer trait. [dependencies] imp

Eduard Baturin 2 Sep 6, 2022