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

Thousands separator problem #529

Closed
w17 opened this issue Jun 28, 2017 · 8 comments
Closed

Thousands separator problem #529

w17 opened this issue Jun 28, 2017 · 8 comments

Comments

@w17
Copy link

w17 commented Jun 28, 2017

I found some problems using library in farmanager project for {i:n} format.

  1. [Bug]
    Thousands separator is always char in library. It caused problem when separator is unicode character wider than 1 byte. It is very possible in windows case.

  2. [Feature request]
    For now there is no way to customize separator manually.
    In farmanager thousands separator is configurable [optional].
    Is it possible to pass that custom value to library?

There is link to discussion on farmanager bugtracker: http://bugs.farmanager.com/view.php?id=3382

@vitaut
Copy link
Contributor

vitaut commented Jul 1, 2017

Both issues are addressed in the new experimental version of the library. This version is located in the std branch and described in the standards proposal http://fmtlib.net/Text%20Formatting.html.

The first issue is solved by using C++ locales that support wide thousands separator character.

Thousands separator can be customized by passing a custom locale via a buffer.

@w17
Copy link
Author

w17 commented Jul 1, 2017

Can that fatures arrive in the release?

@vitaut
Copy link
Contributor

vitaut commented Jul 2, 2017

Yes, these features/fixes will be a part of the next major release (since replacing C with C++ locales is a breaking change).

@vitaut
Copy link
Contributor

vitaut commented Sep 4, 2017

Fixed in the std branch.

@vitaut vitaut closed this as completed Sep 4, 2017
@cruisercoder
Copy link

Is there a way to limit the width for thousand separated fields?

fmt::format("{:<5n}", 12345678) // want 12,34 but get 12,345,678

@vitaut
Copy link
Contributor

vitaut commented Oct 3, 2019

Is there a way to limit the width for thousand separated fields?

Yes, use format_to_n: https://fmt.dev/latest/api.html#_CPPv2N3fmt11format_to_nE8OutputItNSt6size_tERK1SDpRK4Args

@cruisercoder
Copy link

good to know, but I frequently use fmt for fixed with tables like below. Can I control the padding (not necessarily overflow) for the 2nd item?

fmt::format("{:<50.50}{:<12.12}{<:12.12}\n", "ITEM", "COST","RATING") // header
fmt::format("{:<50.50}{:<12n}{<:12.12}\n", item,cost,rating);

@vitaut
Copy link
Contributor

vitaut commented Oct 3, 2019

Can I control the padding (not necessarily overflow) for the 2nd item?

You can control the minimum width but not the maximum width. The latter can be controlled via a nested call to format.

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