Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifier 'n' does not consider the grouping() from the locale #1393

Closed
dlaugt opened this issue Nov 2, 2019 · 0 comments
Closed

Specifier 'n' does not consider the grouping() from the locale #1393

dlaugt opened this issue Nov 2, 2019 · 0 comments

Comments

@dlaugt
Copy link
Contributor

dlaugt commented Nov 2, 2019

C++ locale has two configurations (thousands_sep() and grouping()) to display thousand separator. fmt is using only thousands_sep(). It would be nice if fmt uses both as stringstream.

struct no_grouping : std::numpunct<char>
{
  std::string do_grouping () const {return "";}
};
std::locale loc (locale ("en-US"), new no_grouping);

std::stringstream ss;
ss.imbue (loc);
ss << 100000;
// gives 100000

fmt::format (loc, "{:n}", 100000);
// gives 100,000
struct special_grouping : std::numpunct<char>
{
  std::string do_grouping () const {return "\03\02";}
};
std::locale loc (locale ("en-US"), new special_grouping);

std::stringstream ss;
ss.imbue (loc);
ss << 100000;
// gives 1,00,000

fmt::format (loc, "{:n}", 100000);
// gives 100,000

For example, the Indian locale is a practical usage in python:

>>> from locale import setlocale, LC_ALL
>>> setlocale(LC_ALL, 'en_IN')
'en_IN'
>>> '{:n}'.format(100000)
'1,00,000'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants