From 8bbe76af3a5427597185ad6207ee6e588d2eb0fd Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 2 Dec 2019 11:36:33 -0800 Subject: Add a missing decimal point in exponent notation with trailing zeros --- include/fmt/format.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'include/fmt/format.h') diff --git a/include/fmt/format.h b/include/fmt/format.h index 398c2a77..600b0eba 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1145,10 +1145,11 @@ template class float_writer { if (specs_.format == float_format::exp) { // Insert a decimal point after the first digit and add an exponent. *it++ = static_cast(*digits_); - if (num_digits_ > 1) *it++ = decimal_point_; - it = copy_str(digits_ + 1, digits_ + num_digits_, it); int num_zeros = specs_.precision - num_digits_; - if (num_zeros > 0 && specs_.trailing_zeros) + bool trailing_zeros = num_zeros > 0 && specs_.trailing_zeros; + if (num_digits_ > 1 || trailing_zeros) *it++ = decimal_point_; + it = copy_str(digits_ + 1, digits_ + num_digits_, it); + if (trailing_zeros) it = std::fill_n(it, num_zeros, static_cast('0')); *it++ = static_cast(specs_.upper ? 'E' : 'e'); return write_exponent(full_exp - 1, it); -- cgit v1.2.3