From 5060568f7218b632ebc0bb086722a9eba3276790 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 27 Jan 2018 17:56:19 -0800 Subject: [PATCH] %.f should have zero precision, not default precision --- include/fmt/printf.h | 2 ++ test/printf-test.cc | 3 +++ 2 files changed, 5 insertions(+) diff --git a/include/fmt/printf.h b/include/fmt/printf.h index 28630a03..2455cb1e 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -454,6 +454,8 @@ void basic_printf_context::format() { ++it; spec.precision_ = visit(internal::PrintfPrecisionHandler(), get_arg(it)); + } else { + spec.precision_ = 0; } } diff --git a/test/printf-test.cc b/test/printf-test.cc index 288b0b28..e5dc413a 100644 --- a/test/printf-test.cc +++ b/test/printf-test.cc @@ -397,6 +397,9 @@ TEST(PrintfTest, long_long) { TEST(PrintfTest, Float) { EXPECT_PRINTF("392.650000", "%f", 392.65); + EXPECT_PRINTF("392.65", "%.2f", 392.65); + EXPECT_PRINTF("392.6", "%.1f", 392.65); + EXPECT_PRINTF("393", "%.f", 392.65); EXPECT_PRINTF("392.650000", "%F", 392.65); char buffer[BUFFER_SIZE]; safe_sprintf(buffer, "%e", 392.65);