Skip to content
Snippets Groups Projects
Unverified Commit 67a2c22a authored by Shaopeng Wang's avatar Shaopeng Wang Committed by GitHub
Browse files

Fix format of Fixed128. (#122)

parent 057207c2
No related branches found
No related tags found
No related merge requests found
......@@ -228,7 +228,8 @@ impl Bounded for Fixed128 {
impl rstd::fmt::Debug for Fixed128 {
#[cfg(feature = "std")]
fn fmt(&self, f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
write!(f, "Fixed128({},{})", self.0 / DIV, self.0 % DIV)
let fractional = format!("{:0>18}", (self.0 % DIV).abs());
write!(f, "Fixed128({},{})", self.0 / DIV, fractional)
}
#[cfg(not(feature = "std"))]
......@@ -576,4 +577,14 @@ mod tests {
assert!(!zero.is_positive());
assert!(!zero.is_negative());
}
#[test]
fn fmt_should_work() {
let positive = Fixed128::from_parts(1000000000000000001);
assert_eq!(format!("{:?}", positive), "Fixed128(1,000000000000000001)");
let negative = Fixed128::from_parts(-1000000000000000001);
assert_eq!(format!("{:?}", negative), "Fixed128(-1,000000000000000001)");
let zero = Fixed128::zero();
assert_eq!(format!("{:?}", zero), "Fixed128(0,000000000000000000)");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment