mirror of
https://github.com/PaddiM8/kalker.git
synced 2024-11-07 16:34:21 +01:00
Trim trailing zeroes also for custom precision numbers
This commit is contained in:
parent
074643ea4f
commit
5f9ff40279
@ -247,20 +247,27 @@ impl KalkValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_string_big(&self) -> String {
|
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 let KalkValue::Number(real, imaginary, _) = self {
|
||||||
if !self.has_imaginary() {
|
if !self.has_imaginary() {
|
||||||
return real.to_string();
|
return trim_num(real.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
let sign = if imaginary < &0f64 { "-" } else { "+" };
|
let sign = if imaginary < &0f64 { "-" } else { "+" };
|
||||||
format!(
|
format!(
|
||||||
"{} {} {}i",
|
"{} {} {}i",
|
||||||
spaced(&real.to_string()),
|
spaced(&trim_num(real.to_string())),
|
||||||
sign,
|
sign,
|
||||||
spaced(&imaginary.to_string())
|
spaced(&trim_num(imaginary.to_string()))
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
self.to_string()
|
trim_num(self.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user