diff --git a/include/fmt/format.h b/include/fmt/format.h index ea6678db..23d46d07 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1453,8 +1453,9 @@ template class basic_writer { }; void on_num() { - int num_digits = internal::count_digits(abs_value); char_type sep = internal::thousands_sep(writer.locale_); + if (!sep) return on_dec(); + int num_digits = internal::count_digits(abs_value); int size = num_digits + sep_size * ((num_digits - 1) / 3); writer.write_int(size, get_prefix(), specs, num_writer{abs_value, size, sep}); diff --git a/test/locale-test.cc b/test/locale-test.cc index 91508e77..37d4687b 100644 --- a/test/locale-test.cc +++ b/test/locale-test.cc @@ -44,5 +44,9 @@ TEST(LocaleTest, WFormat) { EXPECT_EQ(L"1~234~567", fmt::format(loc, L"{:n}", 1234567)); fmt::format_arg_store as{1234567}; EXPECT_EQ(L"1~234~567", fmt::vformat(loc, L"{:n}", fmt::wformat_args(as))); + auto sep = + std::use_facet>(std::locale("C")).thousands_sep(); + auto result = sep == ',' ? L"1,234,567" : L"1234567"; + EXPECT_EQ(result, fmt::format(std::locale("C"), L"{:n}", 1234567)); } #endif // FMT_STATIC_THOUSANDS_SEPARATOR