From 0fd22fbd7be9efd03c82570a778dbb5cde20cad4 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 6 Mar 2021 11:31:54 +0530 Subject: reduce display width of FloatData --- src/habit/float.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/habit/float.rs b/src/habit/float.rs index 7e98b18..2d61fc0 100644 --- a/src/habit/float.rs +++ b/src/habit/float.rs @@ -45,7 +45,13 @@ impl fmt::Display for FloatData { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let characteristic = self.value / (10 * self.precision as u32); let mantissa = self.value % (10 * self.precision as u32); - let s = format!("{}.{}", characteristic, mantissa); + let s = if characteristic == 0 { + format!(".{}", mantissa) + } else if mantissa == 0 { + format!("{}", characteristic) + } else { + format!("{}.{}", characteristic, mantissa) + }; write!(f, "{:^3}", s) } } -- cgit v1.2.3