From 946498cfbc5fb633b1f12683ffaa80279f0a49cd Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Fri, 19 Apr 2019 14:48:42 -0700 Subject: [PATCH] Fix handling of zero precision --- include/fmt/format-inl.h | 2 +- test/grisu-test.cc | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 4130107e..a074f6ae 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -610,7 +610,7 @@ struct fixed_handler { uint64_t error, int, bool integral) { FMT_ASSERT(remainder < divisor, ""); buf[size++] = digit; - if (size != precision) return digits::more; + if (size < precision) return digits::more; if (!integral) { // Check if error * 2 < divisor with overflow prevention. // The check is not needed for the integral part because error = 1 diff --git a/test/grisu-test.cc b/test/grisu-test.cc index 746e90ba..8e3c6dc1 100644 --- a/test/grisu-test.cc +++ b/test/grisu-test.cc @@ -52,3 +52,7 @@ TEST(GrisuTest, Prettify) { EXPECT_EQ("12.34", fmt::format("{}", 1234e-2)); EXPECT_EQ("0.001234", fmt::format("{}", 1234e-6)); } + +TEST(GrisuTest, ZeroPrecision) { + EXPECT_EQ("1", fmt::format("{:.0}", 1.0)); +}