Skip to content

Commit cbac016

Browse files
manyleggedvitaut
authored andcommitted
%.f should have zero precision, not default precision
1 parent c03f55e commit cbac016

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

fmt/printf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,8 @@ void PrintfFormatter<Char, AF>::format(BasicCStringRef<Char> format_str) {
439439
} else if (*s == '*') {
440440
++s;
441441
spec.precision_ = internal::PrecisionHandler().visit(get_arg(s));
442+
} else {
443+
spec.precision_ = 0;
442444
}
443445
}
444446

test/printf-test.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,9 @@ TEST(PrintfTest, LongLong) {
401401

402402
TEST(PrintfTest, Float) {
403403
EXPECT_PRINTF("392.650000", "%f", 392.65);
404+
EXPECT_PRINTF("392.65", "%.2f", 392.65);
405+
EXPECT_PRINTF("392.6", "%.1f", 392.65);
406+
EXPECT_PRINTF("393", "%.f", 392.65);
404407
EXPECT_PRINTF("392.650000", "%F", 392.65);
405408
EXPECT_PRINTF("392.65", "%s", 392.65);
406409
char buffer[BUFFER_SIZE];

0 commit comments

Comments
 (0)