From 9a99d7d40ac15a792d73bfe73a73ec2b87b887e4 Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Tue, 2 Apr 2019 18:13:21 +0530 Subject: add width with fmt --- src/main.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 774ea1a..b9fdbd3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,13 +87,13 @@ fn pprint(ans: f64) { let ans_string = format!("{:.*}", CONFIGURATION.fix, ans); let ans_vector: Vec<&str> = ans_string.split(".").collect(); match ans_vector.len() { - 1 => println!("{}", thousand_sep(ans_vector[0])), - 2 => println!("{}.{}", thousand_sep(ans_vector[0]),ans_vector[1]), + 1 => println!("{:>10}", thousand_sep(ans_vector[0])), + 2 => println!("{:>10}.{}", thousand_sep(ans_vector[0]),ans_vector[1]), _ => () } } -fn thousand_sep(inp:&str) -> String { +fn thousand_sep(inp: &str) -> String { let mut result_string = String::new(); for (i,c) in inp.to_string().chars().rev().enumerate(){ if i % 3 == 0 && i != 0 && c.to_string() != "-"{ @@ -101,11 +101,6 @@ fn thousand_sep(inp:&str) -> String { } result_string.push(c) } - let arrange = 10_usize - result_string.len() as usize; - - if arrange > 0 { - result_string.push_str(" ".repeat(arrange as usize).as_str()) - } result_string.chars().rev().collect::() } -- cgit v1.2.3