Fix unexpected trailing decimal point (#1153)
This commit is contained in:
parent
ccc318e807
commit
77d6036cd5
@ -1187,12 +1187,14 @@ It grisu_prettify(const char* digits, int size, int exp, It it,
|
||||
} else if (full_exp > 0) {
|
||||
// 1234e-2 -> 12.34[0+]
|
||||
it = copy_str<Char>(digits, digits + full_exp, it);
|
||||
*it++ = static_cast<Char>('.');
|
||||
if (!params.trailing_zeros) {
|
||||
// Remove trailing zeros.
|
||||
while (size > full_exp && digits[size - 1] == '0') --size;
|
||||
if (size != full_exp)
|
||||
*it++ = static_cast<Char>('.');
|
||||
return copy_str<Char>(digits + full_exp, digits + size, it);
|
||||
}
|
||||
*it++ = static_cast<Char>('.');
|
||||
it = copy_str<Char>(digits + full_exp, digits + size, it);
|
||||
if (params.num_digits > size) {
|
||||
// Add trailing zeros.
|
||||
|
@ -406,6 +406,8 @@ TEST(PrintfTest, Float) {
|
||||
EXPECT_PRINTF(buffer, "%E", 392.65);
|
||||
EXPECT_PRINTF("392.65", "%g", 392.65);
|
||||
EXPECT_PRINTF("392.65", "%G", 392.65);
|
||||
EXPECT_PRINTF("392", "%g", 392.0);
|
||||
EXPECT_PRINTF("392", "%G", 392.0);
|
||||
safe_sprintf(buffer, "%a", -392.65);
|
||||
EXPECT_EQ(buffer, format("{:a}", -392.65));
|
||||
safe_sprintf(buffer, "%A", -392.65);
|
||||
|
Loading…
Reference in New Issue
Block a user