I'm using "{:L}" to print locale-specific thousands separators when printing floating point numbers.
std::cout << std::format(std::locale("en_US.UTF-8"), "{:L}", 12345.678 );
Correctly produces:
12,345.678
However, I'm noticing some unexpected behavior from gcc when printing negative numbers.
std::cout << std::format(std::locale("en_US.UTF-8"), "{:L}", -123.45 );
Produces:
-,123.45
Am I wrong to expect -123.45, since there are no thousands? Does gcc have a bug?
Godbolt example
The authoritative Jonathan Wakely has confirmed that this is currently a bug in libstdc++, known to fail in gcc 13.4, 14.3, 15.1
A leading + or - or in a formatted floating point number is mistakenly considered a digit.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120548
This is now reported as "Fixed" in gcc 13.5, 14.4 and 15.2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With