Use the decimal point from locale

This commit is contained in:
Victor Zverovich
2019-07-03 17:55:00 -07:00
parent 476f25cd81
commit bc14c6ee20
5 changed files with 45 additions and 18 deletions
-4
View File
@@ -1447,10 +1447,6 @@ TEST(FormatterTest, FormatDouble) {
EXPECT_EQ(buffer, format("{:A}", -42.0));
}
TEST(FormatterTest, FormatDoubleLocale) {
EXPECT_EQ("1.23", format("{:n}", 1.23));
}
TEST(FormatterTest, PrecisionRounding) {
EXPECT_EQ("0", format("{:.0f}", 0.0));
EXPECT_EQ("0", format("{:.0f}", 0.01));
+6
View File
@@ -11,9 +11,15 @@
#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
template <typename Char> struct numpunct : std::numpunct<Char> {
protected:
Char do_decimal_point() const FMT_OVERRIDE { return '?'; }
Char do_thousands_sep() const FMT_OVERRIDE { return '~'; }
};
TEST(LocaleTest, DoubleDecimalPoint) {
std::locale loc(std::locale(), new numpunct<char>());
EXPECT_EQ("1?23", fmt::format(loc, "{:n}", 1.23));
}
TEST(LocaleTest, Format) {
std::locale loc(std::locale(), new numpunct<char>());
EXPECT_EQ("1,234,567", fmt::format(std::locale(), "{:n}", 1234567));