From 0fe0b15e71fdff46ff29166636a7e2fcb3193990 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 13 Jan 2021 16:48:07 -0800 Subject: [PATCH] Fix handling of # in width computation --- include/fmt/format.h | 2 +- test/format-test.cc | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 9ec77ab7..e220ef97 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1925,7 +1925,7 @@ OutputIt write_float(OutputIt out, const DecimalFP& fp, #endif if (fspecs.showpoint) { if (num_zeros <= 0 && fspecs.format != float_format::fixed) num_zeros = 1; - if (num_zeros > 0) size += to_unsigned(num_zeros); + if (num_zeros > 0) size += to_unsigned(num_zeros) + 1; } return write_padded(out, specs, size, [&](iterator it) { if (sign) *it++ = static_cast(data::signs[sign]); diff --git a/test/format-test.cc b/test/format-test.cc index e821e773..dd3db801 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -869,6 +869,7 @@ TEST(FormatterTest, Width) { EXPECT_EQ("x ", format("{0:11}", 'x')); EXPECT_EQ("str ", format("{0:12}", "str")); EXPECT_EQ(fmt::format("{:*^5}", "🤡"), "**🤡**"); + EXPECT_EQ(fmt::format("{:#6}", 42.0), " 42.0"); } template inline T const_check(T value) { return value; }