Skip to content

Commit

Permalink
Fix handling of locale separators in FP formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Apr 12, 2022
1 parent 395cf0f commit 192f79a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -2249,7 +2249,7 @@ FMT_CONSTEXPR20 auto do_write_float(OutputIt out, const DecimalFP& fp,
if (num_zeros > 0) size += to_unsigned(num_zeros);
}
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<Char>(it, significand, significand_size,
Expand Down
9 changes: 5 additions & 4 deletions test/xchar-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,11 @@ template <typename Char> struct small_grouping : std::numpunct<Char> {

TEST(locale_test, localized_double) {
auto loc = std::locale(std::locale(), new numpunct<char>());
EXPECT_EQ("1?23", fmt::format(loc, "{:L}", 1.23));
EXPECT_EQ("1?230000", fmt::format(loc, "{:Lf}", 1.23));
EXPECT_EQ("1~234?5", fmt::format(loc, "{:L}", 1234.5));
EXPECT_EQ("12~000", fmt::format(loc, "{:L}", 12000.0));
EXPECT_EQ(fmt::format(loc, "{:L}", 1.23), "1?23");
EXPECT_EQ(fmt::format(loc, "{:Lf}", 1.23), "1?230000");
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");
}

TEST(locale_test, format) {
Expand Down

0 comments on commit 192f79a

Please sign in to comment.