mirror of
https://github.com/fmtlib/fmt.git
synced 2025-02-05 00:40:12 +00:00
Fix formatting of 0.0 with (#1210)
This commit is contained in:
parent
9d97201ede
commit
260c115908
@ -685,7 +685,7 @@ FMT_API bool grisu_format(Double value, buffer<char>& buf, int precision,
|
|||||||
FMT_ASSERT(value >= 0, "value is negative");
|
FMT_ASSERT(value >= 0, "value is negative");
|
||||||
bool fixed = (options & grisu_options::fixed) != 0;
|
bool fixed = (options & grisu_options::fixed) != 0;
|
||||||
if (value <= 0) { // <= instead of == to silence a warning.
|
if (value <= 0) { // <= instead of == to silence a warning.
|
||||||
if (precision < 0 || !fixed) {
|
if (precision <= 0 || !fixed) {
|
||||||
exp = 0;
|
exp = 0;
|
||||||
buf.push_back('0');
|
buf.push_back('0');
|
||||||
} else {
|
} else {
|
||||||
|
@ -1452,6 +1452,7 @@ TEST(FormatterTest, FormatDouble) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(FormatterTest, PrecisionRounding) {
|
TEST(FormatterTest, PrecisionRounding) {
|
||||||
|
EXPECT_EQ("0", format("{:.0f}", 0.0));
|
||||||
EXPECT_EQ("0", format("{:.0f}", 0.1));
|
EXPECT_EQ("0", format("{:.0f}", 0.1));
|
||||||
EXPECT_EQ("0.000", format("{:.3f}", 0.00049));
|
EXPECT_EQ("0.000", format("{:.3f}", 0.00049));
|
||||||
EXPECT_EQ("0.001", format("{:.3f}", 0.0005));
|
EXPECT_EQ("0.001", format("{:.3f}", 0.0005));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user