From 260c1159088a9622f374d362353b3d114d8654bf Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 30 Jun 2019 06:54:41 -0700 Subject: [PATCH] Fix formatting of 0.0 with (#1210) --- include/fmt/format-inl.h | 2 +- test/format-test.cc | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 0ce96b28..5cda7307 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -685,7 +685,7 @@ FMT_API bool grisu_format(Double value, buffer& buf, int precision, FMT_ASSERT(value >= 0, "value is negative"); bool fixed = (options & grisu_options::fixed) != 0; if (value <= 0) { // <= instead of == to silence a warning. - if (precision < 0 || !fixed) { + if (precision <= 0 || !fixed) { exp = 0; buf.push_back('0'); } else { diff --git a/test/format-test.cc b/test/format-test.cc index 2b9b5857..da2fd721 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1452,6 +1452,7 @@ TEST(FormatterTest, FormatDouble) { } TEST(FormatterTest, PrecisionRounding) { + EXPECT_EQ("0", format("{:.0f}", 0.0)); EXPECT_EQ("0", format("{:.0f}", 0.1)); EXPECT_EQ("0.000", format("{:.3f}", 0.00049)); EXPECT_EQ("0.001", format("{:.3f}", 0.0005));