diff --git a/stl/inc/format b/stl/inc/format index 53b960dbdd6..a54479bcbe8 100644 --- a/stl/inc/format +++ b/stl/inc/format @@ -2145,6 +2145,8 @@ _NODISCARD _OutputIt _Fmt_write( case 'g': if (_Precision == -1) { _Precision = 6; + } else if (_Precision == 0) { + _Precision = 1; } _Format = chars_format::general; break; diff --git a/tests/std/tests/P0645R10_text_formatting_formatting/test.cpp b/tests/std/tests/P0645R10_text_formatting_formatting/test.cpp index 4273f2f9909..a0b2e041bdf 100644 --- a/tests/std/tests/P0645R10_text_formatting_formatting/test.cpp +++ b/tests/std/tests/P0645R10_text_formatting_formatting/test.cpp @@ -835,6 +835,7 @@ void test_float_specs() { assert(format(STR("{:3}"), Float{0}) == STR(" 0")); assert(format(STR("{:#9G}"), Float{12.2}) == STR(" 12.2000")); assert(format(STR("{:#12g}"), Float{1'000'000}) == STR(" 1.00000e+06")); + assert(format(STR("[{:#6.0g}]"), 1.234e-37) == STR("[1.e-37]")); // Precision Float value = 1234.52734375;