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

fmt::print() does not honor locale? #305

Closed
rogerdahl opened this issue Apr 16, 2016 · 4 comments
Closed

fmt::print() does not honor locale? #305

rogerdahl opened this issue Apr 16, 2016 · 4 comments

Comments

@rogerdahl
Copy link

Thank you for cppformat. It's awesome.

Is it possible to get cppformat to honor the current locale?

locale::global(locale("en_US.utf8"));
cout.imbue(locale("en_US.utf8"));
cout << "iostream: " << 1234567 << endl;
fmt::print("cppformat: {}\n", 1234567);

iostream: 1,234,567
cppformat: 1234567
@vitaut
Copy link
Contributor

vitaut commented Apr 18, 2016

Thanks for a nice feedback.

fmt::print and fmt::format follow Python str.format's conventions with the default integer format being locale-independent:

>>> from locale import setlocale, LC_ALL
>>> '{}'.format(1234567)
'1234567'
>>> setlocale(LC_ALL, 'en_US.utf8')
'en_US.utf8'
>>> '{}'.format(1234567)
'1234567'
>>> '{:n}'.format(1234567)
'1,234,567'

I've implemented the n format specifier in f68771a so this should work now:

  std::setlocale(LC_ALL, "en_US.utf8");
  fmt::print("cppformat: {:n}\n", 1234567);

@tearfur
Copy link

tearfur commented Sep 15, 2023

Hi @vitaut, sorry if I missed something, it seems like the n specifier is currently undocumented.

I'd be happy to create a PR for updating the documentation, but I'm not confident I can give a good enough description of it. So could you please add it in?

@vitaut
Copy link
Contributor

vitaut commented Sep 15, 2023

The n specifier has been renamed to L per feedback from the C++ committee.

@tearfur
Copy link

tearfur commented Sep 15, 2023

Ah I see, thanks.

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

3 participants