https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110749
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> --- If you use std::fixed as the floatfield format then std::setprecision specifies the number of digits after the decimal point: os << (0.0 > value ? '-' : '0') << std::setw(cv.size - 1) << std::setfill('0') << std::setprecision(cv.pos) << std::fixed << std::abs(value); You don't need to handle the -'- sign yourself: os << std::setw(cv.size) << std::internal << std::setfill('0') << std::fixed << std::setprecision(cv.pos) << value; This matches the output of printf("%0*.*f", cv.size, cv.pos, value)