diff options
author | Akshay <nerdy@peppe.rs> | 2021-03-06 11:31:54 +0530 |
---|---|---|
committer | Akshay <nerdy@peppe.rs> | 2021-03-06 11:31:54 +0530 |
commit | 0fd22fbd7be9efd03c82570a778dbb5cde20cad4 (patch) | |
tree | 7f63dc113583c66008768ca9865c3ad647739c7a | |
parent | 22a3f02c0363d911d1cc0b6a53c9e5c801a37267 (diff) |
reduce display width of FloatDatafeat/float
-rw-r--r-- | src/habit/float.rs | 8 |
1 files changed, 7 insertions, 1 deletions
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) } } |