Skip to content

Commit b6c0f26

Browse files
committed
Fix handling of unspecified <format> precision
1 parent 79ef9ab commit b6c0f26

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

include/boost/decimal/format.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ constexpr auto parse_impl(ParseContext &ctx)
4242
{
4343
auto sign_character = format_sign_option::minus;
4444
auto it {ctx.begin()};
45-
int ctx_precision = 6;
45+
int ctx_precision = -1;
4646
boost::decimal::chars_format fmt = boost::decimal::chars_format::general;
4747
bool is_upper = false;
4848
int padding_digits = 0;
@@ -207,7 +207,15 @@ struct formatter<T>
207207
// LCOV_EXCL_STOP
208208
}
209209

210-
const auto r = to_chars(buffer_front, buffer.data() + buffer.size(), v, fmt, ctx_precision);
210+
boost::decimal::to_chars_result r {};
211+
if (ctx_precision != -1)
212+
{
213+
r = to_chars(buffer_front, buffer.data() + buffer.size(), v, fmt, ctx_precision);
214+
}
215+
else
216+
{
217+
r = to_chars(buffer_front, buffer.data() + buffer.size(), v, fmt);
218+
}
211219

212220
std::string s(buffer.data(), static_cast<std::size_t>(r.ptr - buffer.data()));
213221

0 commit comments

Comments
 (0)