6 releases

Uses old Rust 2015

0.3.3 Apr 22, 2017
0.3.2 Apr 22, 2017
0.2.0 Apr 22, 2017
0.1.0 Apr 22, 2017

#190 in Value formatting

Download history 2288/week @ 2024-08-15 2560/week @ 2024-08-22 2455/week @ 2024-08-29 2212/week @ 2024-09-05 2275/week @ 2024-09-12 2177/week @ 2024-09-19 2485/week @ 2024-09-26 4492/week @ 2024-10-03 4736/week @ 2024-10-10 4868/week @ 2024-10-17 3917/week @ 2024-10-24 3789/week @ 2024-10-31 4213/week @ 2024-11-07 3996/week @ 2024-11-14 3541/week @ 2024-11-21 3075/week @ 2024-11-28

15,382 downloads per month
Used in 17 crates (13 directly)

MIT license

21KB
548 lines

crates.io

english-numbers

Convert your boring old i64's to shiny new String's!

Use this libary to spell out numbers, as you would when reading them. Choose from a variety of formatting options, from title-case with spaces, commas, and 'and''s where they should be, to nothing but lowercase letters, and everything in between.

Important Functions

fn convert(val: i64, fmt: Formatting) -> String

This is the base function, set your val, and then play around with the options in the Formatting struct to get the precise output you desire.

fn convert_all_fmt(val: i64) -> String

Use this function to get an output with all the bells and whistles, example:

123456789 -> "One Hundred and Twenty-Three Million, Four Hundred and Fifty-Six Thousand, Seven Hundred and Eighty-Nine"

Much better, right?

fn convert_no_fmt(val: i64) -> String

Use this function to get an output as bare-bones as possible, no spaces, no hyphens, no nothing! Example:

9223372036854775807 -> "ninequintilliontwohundredtwentythreequadrillionthreehundredseventytwotrillionthirtysixbillioneighthundredfiftyfourmillionsevenhundredseventyfivethousandeighthundredseven"

If that isn't easy to read, I don't know what is!

fn convert_long(val: i64, fmt: Formatting) -> String

Use this to convert using the "long" numbering format, used in the EU and French Canada. Example:

1000000000000 -> "One Thousand Million"

Important Structs

struct Formatting
{
    pub title_case: bool,
    pub spaces: bool,
    pub conjunctions: bool,
    pub commas: bool,
    pub dashes: bool,
}

This struct handles all the formatting options that you can specify, feel free to mix-and-match to your needs!

Use the functions Formatting::all() and Formatting::none() to get the pre-built formatting values you expect.

No runtime deps