mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-24 12:14:26 +00:00
Don't remove trailing zeros with #
This commit is contained in:
parent
e06ae32294
commit
4fd95e4b4d
@ -1131,7 +1131,7 @@ int format_float(T value, int precision, float_specs specs, buffer<char>& buf) {
|
||||
if (grisu_gen_digits(normalized, 1, exp, handler) == digits::error)
|
||||
return snprintf_float(value, precision, specs, buf);
|
||||
int num_digits = handler.size;
|
||||
if (!fixed) {
|
||||
if (!fixed && !specs.showpoint) {
|
||||
// Remove trailing zeros.
|
||||
while (num_digits > 0 && buf[num_digits - 1] == '0') {
|
||||
--num_digits;
|
||||
|
@ -761,6 +761,7 @@ TEST(FormatterTest, HashFlag) {
|
||||
EXPECT_EQ("-42.0", format("{0:#}", -42.0l));
|
||||
EXPECT_EQ("4.e+01", format("{:#.0e}", 42.0));
|
||||
EXPECT_EQ("0.", format("{:#.0f}", 0.01));
|
||||
EXPECT_EQ("0.50", format("{:#.2g}", 0.5));
|
||||
auto s = format("{:#.0f}", 0.5); // MSVC's printf uses wrong rounding mode.
|
||||
EXPECT_TRUE(s == "0." || s == "1.");
|
||||
EXPECT_THROW_MSG(format("{0:#", 'c'), format_error,
|
||||
|
Loading…
Reference in New Issue
Block a user