english_numbers/lib.rs
1//! # english-numbers
2//!
3//! A library for converting integers to their written-english formats.
4//! Supports both American "short" and European "long" number formats.
5
6mod groups;
7mod hundreds;
8mod tens;
9
10mod words;
11mod formatting;
12
13#[cfg(test)]
14mod test;
15
16pub use formatting::Formatting;
17
18/// Converts a number to it's written format, using "short" format.
19///
20/// Arguments:
21/// * `val`: the `i64` to convert
22/// * `fmt`: the formatting options to use
23pub fn convert(val: i64, fmt: Formatting) -> String
24{
25 groups::Groups::new(val)
26 .build(false)
27 .build(fmt)
28}
29
30/// Converts a number to it's written format, using "short" format with all formatting options enabled.
31///
32/// # Arguments:
33/// * `val` - the `i64` to convert
34pub fn convert_all_fmt(val: i64) -> String
35{
36 groups::Groups::new(val)
37 .build(false)
38 .build(Formatting::all())
39}
40
41/// Converts a number to it's written format, using "short" format with no formatting options enabled.
42///
43/// # Arguments:
44/// * `val` - the `i64` to convert
45pub fn convert_no_fmt(val: i64) -> String
46{
47 groups::Groups::new(val)
48 .build(false)
49 .build(Formatting::none())
50}
51
52/// Converts a number to it's written format, using "long" format.
53///
54/// # Arguments:
55/// * `val` - the `i64` to convert
56/// * `fmt` - the formatting options to use
57pub fn convert_long(val: i64, fmt: Formatting) -> String
58{
59 groups::Groups::new(val)
60 .build(true)
61 .build(fmt)
62}