Skip to content

Commit

Permalink
reduce display width of FloatData
Browse files Browse the repository at this point in the history
  • Loading branch information
oppiliappan committed Mar 6, 2021
1 parent 22a3f02 commit 0fd22fb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/habit/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 0fd22fb

Please sign in to comment.