mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-05 20:41:06 +00:00
Don't emit decimal point if there are no trailing digits (#1210)
This commit is contained in:
parent
bd3fd3bfda
commit
ab0ba8a9d0
@ -1096,14 +1096,16 @@ It grisu_prettify(const char* digits, int size, int exp, It it,
|
||||
} else {
|
||||
// 1234e-6 -> 0.001234
|
||||
*it++ = static_cast<Char>('0');
|
||||
*it++ = static_cast<Char>('.');
|
||||
int num_zeros = -full_exp;
|
||||
if (params.num_digits >= 0 && params.num_digits < num_zeros)
|
||||
num_zeros = params.num_digits;
|
||||
it = std::fill_n(it, num_zeros, static_cast<Char>('0'));
|
||||
if (!params.trailing_zeros)
|
||||
while (size > 0 && digits[size - 1] == '0') --size;
|
||||
it = copy_str<Char>(digits, digits + size, it);
|
||||
if (num_zeros != 0 || size != 0) {
|
||||
*it++ = static_cast<Char>('.');
|
||||
it = std::fill_n(it, num_zeros, static_cast<Char>('0'));
|
||||
it = copy_str<Char>(digits, digits + size, it);
|
||||
}
|
||||
}
|
||||
return it;
|
||||
}
|
||||
|
@ -1453,6 +1453,7 @@ TEST(FormatterTest, FormatDouble) {
|
||||
|
||||
TEST(FormatterTest, PrecisionRounding) {
|
||||
EXPECT_EQ("0", format("{:.0f}", 0.0));
|
||||
EXPECT_EQ("0", format("{:.0f}", 0.01));
|
||||
EXPECT_EQ("0", format("{:.0f}", 0.1));
|
||||
EXPECT_EQ("0.000", format("{:.3f}", 0.00049));
|
||||
EXPECT_EQ("0.001", format("{:.3f}", 0.0005));
|
||||
|
Loading…
Reference in New Issue
Block a user