aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs32
1 files changed, 9 insertions, 23 deletions
diff --git a/src/main.rs b/src/main.rs
index 4f5b4fa..774ea1a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,20 +1,7 @@
1/* 1/*
2 eva - an easy to use calculator REPL similar to bc(1) 2 * eva - an easy to use calculator REPL similar to bc(1)
3 Copyright (C) 2019 Akshay Oppiliappan <[email protected]> 3 * Copyright (C) 2019 Akshay Oppiliappan <[email protected]>
4 4 *
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18 */ 5 */
19 6
20// std 7// std
@@ -97,25 +84,24 @@ fn main() {
97} 84}
98 85
99fn pprint(ans: f64) { 86fn pprint(ans: f64) {
100 let ans_string = format!("{}",ans); 87 let ans_string = format!("{:.*}", CONFIGURATION.fix, ans);
101
102 let ans_vector: Vec<&str> = ans_string.split(".").collect(); 88 let ans_vector: Vec<&str> = ans_string.split(".").collect();
103 match ans_vector.len() { 89 match ans_vector.len() {
104 1 => println!("{}",thousand_sep(ans_vector[0])), 90 1 => println!("{}", thousand_sep(ans_vector[0])),
105 2 => println!("{}.{}",thousand_sep(ans_vector[0]),ans_vector[1]), 91 2 => println!("{}.{}", thousand_sep(ans_vector[0]),ans_vector[1]),
106 _ => () 92 _ => ()
107 } 93 }
108} 94}
109 95
110fn thousand_sep(inp:&str) -> String{ 96fn thousand_sep(inp:&str) -> String {
111 let mut result_string = String::new(); 97 let mut result_string = String::new();
112 for (i,c) in inp.to_string().chars().rev().enumerate(){ 98 for (i,c) in inp.to_string().chars().rev().enumerate(){
113 if i % 3 == 0 && i != 0 && c.to_string() != "-"{ 99 if i % 3 == 0 && i != 0 && c.to_string() != "-"{
114 result_string.push_str(","); 100 result_string.push(',');
115 } 101 }
116 result_string.push(c) 102 result_string.push(c)
117 } 103 }
118 let arrange:i16 = CONFIGURATION.fix as i16 - result_string.len() as i16; 104 let arrange = 10_usize - result_string.len() as usize;
119 105
120 if arrange > 0 { 106 if arrange > 0 {
121 result_string.push_str(" ".repeat(arrange as usize).as_str()) 107 result_string.push_str(" ".repeat(arrange as usize).as_str())