Fix handling of locale separators in FP formatting

This commit is contained in:
Victor Zverovich 2022-04-12 08:00:17 -07:00
parent 395cf0f03e
commit 192f79aaae
2 changed files with 6 additions and 5 deletions

View File

@ -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,

View File

@ -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) {