A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/fmtlib/fmt/issues/3794 below:

GitHub · Where software is built

Any chrono duration n where 0 < n < 10⁻ formatted with {:.N%S} receives full precision instead of N decimals. This also holds if adding any number of whole seconds. In other words, any duration where the decimal part should have been rounded to .0, .00, .000 etc. will be printed with all decimals. For example, with {:.2%S}, 4567 milliseconds are printed as 04.56, while 4007 milliseconds are printed as 04.007 (instead of the expected 04.00). 4007000 microseconds are printed as 04.007000 while 4017000 microseconds are printed as 04.01.

If the decimal part is exactly zero (i.e., the duration is a whole number of seconds), there will be one zero more than the specified precision. Thus, 1000 milliseconds will be printed as 01.00 with {:.1%S}, 01.000 with {:.2%S} etc., whilst 1100 milliseconds will be printed as 01.1, 01.10 etc. (as expected) for the same format strings.

Code to reproduce:

#include <fmt/chrono.h>
#include <fmt/core.h>

int main()
{
  constexpr std::chrono::microseconds works{10'001};
  constexpr std::chrono::microseconds fails{9'999};
  fmt::println("{:.2%S} {:.2%S}", works, fails);
}

Expected output:

Actual output:

Godbolt:
https://godbolt.org/z/rncqqGWW3

Tested with recent versions of Clang and GCC. Affects both fmt::format and fmt::println.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4