Added an if expression for the individual case described in fmtlib/fmt/issues/1917.

Adjusts the length of the number to match the precision for the exponential number format.
This commit is contained in:
andargunov 2020-10-06 17:19:54 +03:00
parent 5bcd642bcc
commit 7eb5e3f583

View File

@ -2468,6 +2468,15 @@ int format_float(T value, int precision, float_specs specs, buffer<char>& buf) {
} else {
exp -= cached_exp10;
buf.try_resize(to_unsigned(handler.size));
if ((specs.format == detail::float_format::exp) && (buf.size() > precision)) {
if (exp < 0) {
exp += (buf.size() - precision);
}
else {
exp -= (buf.size() - precision);
}
buf.try_resize(to_unsigned(precision));
}
}
if (!fixed && !specs.showpoint) {
// Remove trailing zeros.