From 2bcc735de3954a7b38c8bb551be41971e70a901c Mon Sep 17 00:00:00 2001 From: PaddiM8 Date: Wed, 1 Jun 2022 02:18:57 +0200 Subject: [PATCH] Trim trailing zeroes also for custom precision numbers --- kalk/src/kalk_value/mod.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/kalk/src/kalk_value/mod.rs b/kalk/src/kalk_value/mod.rs index 852ca87..92562e9 100644 --- a/kalk/src/kalk_value/mod.rs +++ b/kalk/src/kalk_value/mod.rs @@ -247,20 +247,27 @@ impl KalkValue { } pub fn to_string_big(&self) -> String { + fn trim_num(num_str: String) -> String { + num_str + .trim_end_matches('0') + .trim_end_matches('.') + .to_string() + } + if let KalkValue::Number(real, imaginary, _) = self { if !self.has_imaginary() { - return real.to_string(); + return trim_num(real.to_string()); } let sign = if imaginary < &0f64 { "-" } else { "+" }; format!( "{} {} {}i", - spaced(&real.to_string()), + spaced(&trim_num(real.to_string())), sign, - spaced(&imaginary.to_string()) + spaced(&trim_num(imaginary.to_string())) ) } else { - self.to_string() + trim_num(self.to_string()) } }