Skip to content

Commit

Permalink
Fix handling of thousands separator (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jul 11, 2016
1 parent 116914a commit 0e6df7e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@ inline void format_decimal(Char *buffer, UInt value, unsigned num_digits,
}
unsigned index = static_cast<unsigned>(value * 2);
*--buffer = Data::DIGITS[index + 1];
thousands_sep(buffer);
*--buffer = Data::DIGITS[index];
}

Expand Down Expand Up @@ -2780,7 +2781,7 @@ void BasicWriter<Char>::write_int(T value, Spec spec) {
unsigned num_digits = internal::count_digits(abs_value);
fmt::StringRef sep = internal::thousands_sep(std::localeconv());
unsigned size = static_cast<unsigned>(
num_digits + sep.size() * (num_digits - 1) / 3);
num_digits + sep.size() * ((num_digits - 1) / 3));
CharPtr p = prepare_int_buffer(size, spec, prefix, prefix_size) + 1;
internal::format_decimal(get(p), abs_value, 0, internal::ThousandsSep(sep));
break;
Expand Down
4 changes: 3 additions & 1 deletion test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,9 @@ TEST(FormatterTest, FormatIntLocale) {
lconv lc = {};
char sep[] = "--";
lc.thousands_sep = sep;
EXPECT_CALL(mock, localeconv()).WillOnce(testing::Return(&lc));
EXPECT_CALL(mock, localeconv()).Times(3).WillRepeatedly(testing::Return(&lc));
EXPECT_EQ("123", format("{:n}", 123));
EXPECT_EQ("1--234", format("{:n}", 1234));
EXPECT_EQ("1--234--567", format("{:n}", 1234567));
}

Expand Down

0 comments on commit 0e6df7e

Please sign in to comment.