diff options
author | Akshay <[email protected]> | 2021-03-06 06:01:54 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2021-03-06 06:01:54 +0000 |
commit | 0fd22fbd7be9efd03c82570a778dbb5cde20cad4 (patch) | |
tree | 7f63dc113583c66008768ca9865c3ad647739c7a /src/habit | |
parent | 22a3f02c0363d911d1cc0b6a53c9e5c801a37267 (diff) |
reduce display width of FloatDatafeat/float
Diffstat (limited to 'src/habit')
-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 { | |||
45 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 45 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
46 | let characteristic = self.value / (10 * self.precision as u32); | 46 | let characteristic = self.value / (10 * self.precision as u32); |
47 | let mantissa = self.value % (10 * self.precision as u32); | 47 | let mantissa = self.value % (10 * self.precision as u32); |
48 | let s = format!("{}.{}", characteristic, mantissa); | 48 | let s = if characteristic == 0 { |
49 | format!(".{}", mantissa) | ||
50 | } else if mantissa == 0 { | ||
51 | format!("{}", characteristic) | ||
52 | } else { | ||
53 | format!("{}.{}", characteristic, mantissa) | ||
54 | }; | ||
49 | write!(f, "{:^3}", s) | 55 | write!(f, "{:^3}", s) |
50 | } | 56 | } |
51 | } | 57 | } |