From 98699719f85445e0ab4a962c0b1a2a0218289814 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 26 Feb 2023 10:15:16 -0800 Subject: [PATCH] Make # handling consistent with std::format --- include/fmt/format.h | 2 +- test/format-test.cc | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 6ee29e72..657142c4 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2631,7 +2631,7 @@ FMT_CONSTEXPR20 auto do_write_float(OutputIt out, const DecimalFP& f, abort_fuzzing_if(num_zeros > 5000); if (fspecs.showpoint) { ++size; - if (num_zeros <= 0 && fspecs.format != float_format::fixed) num_zeros = 1; + if (num_zeros <= 0 && fspecs.format != float_format::fixed) num_zeros = 0; if (num_zeros > 0) size += to_unsigned(num_zeros); } auto grouping = Grouping(loc, fspecs.locale); diff --git a/test/format-test.cc b/test/format-test.cc index eaf84c52..2c96191b 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -755,8 +755,8 @@ TEST(format_test, hash_flag) { EXPECT_EQ("0x42", fmt::format("{0:#x}", 0x42ull)); EXPECT_EQ("042", fmt::format("{0:#o}", 042ull)); - EXPECT_EQ("-42.0", fmt::format("{0:#}", -42.0)); - EXPECT_EQ("-42.0", fmt::format("{0:#}", -42.0l)); + EXPECT_EQ("-42.", fmt::format("{0:#}", -42.0)); + EXPECT_EQ("-42.", fmt::format("{0:#}", -42.0l)); EXPECT_EQ("4.e+01", fmt::format("{:#.0e}", 42.0)); EXPECT_EQ("0.", fmt::format("{:#.0f}", 0.01)); EXPECT_EQ("0.50", fmt::format("{:#.2g}", 0.5)); @@ -836,7 +836,7 @@ TEST(format_test, width) { EXPECT_EQ("str ", fmt::format("{0:12}", "str")); EXPECT_EQ(fmt::format("{:*^6}", "🤡"), "**🤡**"); EXPECT_EQ(fmt::format("{:*^8}", "你好"), "**你好**"); - EXPECT_EQ(fmt::format("{:#6}", 42.0), " 42.0"); + EXPECT_EQ(fmt::format("{:#6}", 42.0), " 42."); EXPECT_EQ(fmt::format("{:6c}", static_cast('x')), "x "); EXPECT_EQ(fmt::format("{:>06.0f}", 0.00884311), " 0"); }