Skip to content

Commit 642867b

Browse files
committed
Adjust resulting string manipulation
1 parent 54e3f1a commit 642867b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

include/boost/decimal/fmt_format.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,12 @@ struct formatter
268268

269269
if (use_locale)
270270
{
271-
convert_pointer_pair_to_local_locale(const_cast<char*>(s.data()), s.data() + s.size());
271+
// We need approximately 1/3 more space in order to insert the thousands separators,
272+
// but after we have done our processing we need to shrink the string back down
273+
const auto initial_length {s.length()};
274+
s.resize(s.length() * 4 / 3 + 1);
275+
const auto offset {static_cast<std::size_t>(convert_pointer_pair_to_local_locale(const_cast<char*>(s.data()), s.data() + s.length()))};
276+
s.resize(initial_length + offset);
272277
}
273278

274279
return fmt::format_to(ctx.out(), "{}", s);

0 commit comments

Comments
 (0)