Skip to content

Commit

Permalink
Fix localized format for float-point numbers (#3272)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawnZhong authored Jan 15, 2023
1 parent 0f42c17 commit 39971eb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -2637,7 +2637,7 @@ FMT_CONSTEXPR20 auto do_write_float(OutputIt out, const DecimalFP& f,
int num_zeros = fspecs.showpoint ? fspecs.precision - significand_size : 0;
size += 1 + to_unsigned(num_zeros > 0 ? num_zeros : 0);
auto grouping = Grouping(loc, fspecs.locale);
size += to_unsigned(grouping.count_separators(significand_size));
size += to_unsigned(grouping.count_separators(exp));
return write_padded<align::right>(out, specs, size, [&](iterator it) {
if (sign) *it++ = detail::sign<Char>(sign);
it = write_significand(it, significand, significand_size, exp,
Expand Down
3 changes: 3 additions & 0 deletions test/xchar-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ TEST(locale_test, localized_double) {
EXPECT_EQ(fmt::format(loc, "{:L}", 1234.5), "1~234?5");
EXPECT_EQ(fmt::format(loc, "{:L}", 12000.0), "12~000");
EXPECT_EQ(fmt::format(loc, "{:8L}", 1230.0), " 1~230");
EXPECT_EQ(fmt::format(loc, "{:15.6Lf}", 0.1), " 0?100000");
EXPECT_EQ(fmt::format(loc, "{:15.6Lf}", 1.0), " 1?000000");
EXPECT_EQ(fmt::format(loc, "{:15.6Lf}", 1e3), " 1~000?000000");
}

TEST(locale_test, format) {
Expand Down

0 comments on commit 39971eb

Please sign in to comment.