From 6902bf826c0d1ce84ea819f408209fce0ba65cbc Mon Sep 17 00:00:00 2001 From: Jean Pierre Dudey Date: Wed, 22 Aug 2018 11:26:05 -0400 Subject: [PATCH] Fix negative symbol bug in `FromStr` display implementation. The negative symbol wasn't there when `int_part` was equal to zero. Signed-off-by: Jean Pierre Dudey --- src/util/decimal.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/util/decimal.rs b/src/util/decimal.rs index bdad3a05..6762517e 100644 --- a/src/util/decimal.rs +++ b/src/util/decimal.rs @@ -63,7 +63,11 @@ impl fmt::Display for Decimal { let ten = 10i64.pow(self.exponent as u32); let int_part = self.mantissa / ten; let dec_part = (self.mantissa % ten).abs(); - write!(f, "{}.{:02$}", int_part, dec_part, self.exponent) + if int_part == 0 && self.mantissa < 0 { + write!(f, "-{}.{:02$}", int_part, dec_part, self.exponent) + } else { + write!(f, "{}.{:02$}", int_part, dec_part, self.exponent) + } } }