Added billion

Will add a way to do check up to thousandth's place next
This commit is contained in:
Uttarayan Mondal
2021-03-16 03:40:23 +05:30
parent 404843ac93
commit 7aec2bac7a
3 changed files with 17 additions and 2 deletions
+3
View File
@@ -1,5 +1,8 @@
# ntext-rs # ntext-rs
[![Documentation](https://github.com/uttarayan21/ntext-rs/actions/workflows/docs.yaml/badge.svg)](https://github.com/uttarayan21/ntext-rs/actions/workflows/docs.yaml)
[![Rust Build Test](https://github.com/uttarayan21/ntext-rs/actions/workflows/rust.yaml/badge.svg)](https://github.com/uttarayan21/ntext-rs/actions/workflows/rust.yaml)
Documentation of [ntext-rs](https://uttarayan21.github.io/ntext-rs) generated by cargo doc. Documentation of [ntext-rs](https://uttarayan21.github.io/ntext-rs) generated by cargo doc.
A rust library to get numbers (usize) as words A rust library to get numbers (usize) as words
+1 -1
View File
@@ -30,7 +30,7 @@ impl<'format> Formatting<'format> {
tens_seperator: None, tens_seperator: None,
} }
} }
/// With same formatting for all /// With same formatting for all seperators
pub fn with_seperator(seperator: &'format str) -> Self { pub fn with_seperator(seperator: &'format str) -> Self {
Self { Self {
capitalize: false, capitalize: false,
+13 -1
View File
@@ -47,6 +47,12 @@ fn place_value(number: u8, place: u8, fmt: &Formatting) -> Option<String> {
4 => buffer.push_str("Thousand"), 4 => buffer.push_str("Thousand"),
5 => (), // Souldn't happen 5 => (), // Souldn't happen
6 => buffer.push_str("Million"), 6 => buffer.push_str("Million"),
7 => (),
8 => (),
9 => buffer.push_str("Billion"),
10 => (),
11 => (),
12 => buffer.push_str("Trillion"),
_ => (), _ => (),
}; };
} else { } else {
@@ -57,6 +63,12 @@ fn place_value(number: u8, place: u8, fmt: &Formatting) -> Option<String> {
4 => buffer.push_str("thousand"), 4 => buffer.push_str("thousand"),
5 => (), // Souldn't happen 5 => (), // Souldn't happen
6 => buffer.push_str("million"), 6 => buffer.push_str("million"),
7 => (),
8 => (),
9 => buffer.push_str("billion"),
10 => (),
11 => (),
12 => buffer.push_str("trillion"),
_ => (), _ => (),
} }
} }
@@ -139,7 +151,7 @@ fn tens_place(tens: u8, ones: u8, fmt: &Formatting) -> Option<String> {
pub fn to_text_fmt(number: usize, fmt: &Formatting) -> String { pub fn to_text_fmt(number: usize, fmt: &Formatting) -> String {
let mut numtext: String = String::new(); let mut numtext: String = String::new();
let mut last: Option<u8> = None; let mut last: Option<u8> = None;
let tens_place_holders: [u8; 3] = [2, 5, 7]; let tens_place_holders: [u8; 4] = [2, 5, 7, 10];
let digits: Vec<u8> = number let digits: Vec<u8> = number
.to_string() .to_string()
.chars() .chars()