Why does fmt round 0.5 rounded to 0, for zero decimals?

Viewed 242

I fully implemented the fmt library in my project. But the last bug I found was that values previously where rounded to the higher bound (0.5 -> 1), while they currently are rounded to their lower bound (0.5 -> 0).

When trying to find the cause, I found:

double halfd = 0.5;
std::string str = fmt::format("{:.0f}", halfd ); // result: "0"

float halff = 0.5f
std::string str = fmt::format("{:.0f}", halff ); // result: "0"

I also tried, if the compiler maybe stores 0.5 as 0.49999999999..., but I could not find the cause.

I work with Microsoft Visual Studio 2017 with v140 compiler.

Does anybody know why fmt rounds 0.5 to 0, instead of 1. I previously used the standard printf library.

1 Answers
Related