aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNerdyPepper <[email protected]>2019-04-02 13:43:21 +0100
committerNerdyPepper <[email protected]>2019-04-02 13:43:21 +0100
commit9a99d7d40ac15a792d73bfe73a73ec2b87b887e4 (patch)
tree76eb4019c84187acdd90548e1799232c15c13c21
parent1bd59aba974053ece19739c3983ded0288d679a3 (diff)
add width with fmt
-rw-r--r--src/main.rs11
1 files changed, 3 insertions, 8 deletions
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) {
87 let ans_string = format!("{:.*}", CONFIGURATION.fix, ans); 87 let ans_string = format!("{:.*}", CONFIGURATION.fix, ans);
88 let ans_vector: Vec<&str> = ans_string.split(".").collect(); 88 let ans_vector: Vec<&str> = ans_string.split(".").collect();
89 match ans_vector.len() { 89 match ans_vector.len() {
90 1 => println!("{}", thousand_sep(ans_vector[0])), 90 1 => println!("{:>10}", thousand_sep(ans_vector[0])),
91 2 => println!("{}.{}", thousand_sep(ans_vector[0]),ans_vector[1]), 91 2 => println!("{:>10}.{}", thousand_sep(ans_vector[0]),ans_vector[1]),
92 _ => () 92 _ => ()
93 } 93 }
94} 94}
95 95
96fn thousand_sep(inp:&str) -> String { 96fn thousand_sep(inp: &str) -> String {
97 let mut result_string = String::new(); 97 let mut result_string = String::new();
98 for (i,c) in inp.to_string().chars().rev().enumerate(){ 98 for (i,c) in inp.to_string().chars().rev().enumerate(){
99 if i % 3 == 0 && i != 0 && c.to_string() != "-"{ 99 if i % 3 == 0 && i != 0 && c.to_string() != "-"{
@@ -101,11 +101,6 @@ fn thousand_sep(inp:&str) -> String {
101 } 101 }
102 result_string.push(c) 102 result_string.push(c)
103 } 103 }
104 let arrange = 10_usize - result_string.len() as usize;
105
106 if arrange > 0 {
107 result_string.push_str(" ".repeat(arrange as usize).as_str())
108 }
109 result_string.chars().rev().collect::<String>() 104 result_string.chars().rev().collect::<String>()
110} 105}
111 106