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::format_to_n with locale ':L' does not work correctly #1782

Closed
ghost opened this issue Jul 18, 2020 · 12 comments
Closed

fmt::format_to_n with locale ':L' does not work correctly #1782

ghost opened this issue Jul 18, 2020 · 12 comments

Comments

@ghost
Copy link

ghost commented Jul 18, 2020

I have the issue since I upgraded fmt to version 1.7.1 and built to dll.
In versions before 1.7.x I use "{:n}" for grouping numbers without any issue. Please take a look to the code below for details.

#include <iostream>
#include "fmt/format.h"
int main()
{
	try {
		std::locale::global(std::locale("en-US")); // "en_US.UTF-8";
	}
	catch (const std::exception& e)  {
		fmt::print("Set global locale to \"en-US\" failed: {}", e.what());
	}

	char buff[16] {};
	auto
	out = fmt::format_to_n(buff, std::size(buff), FMT_STRING("{} {}"), 12345, (char)67);
	fmt::print("{}\n", buff); // "12345 C", OK!

	memset(buff, 0, sizeof(buff));
	out = fmt::format_to_n(buff, std::size(buff), FMT_STRING("{:L} {}"), 12345, (char)67);
	fmt::print("{}\n", buff); // print " C,345", I expect "12,345 C".

	return 0;
}
@vitaut
Copy link
Contributor

vitaut commented Jul 18, 2020

Fixed in b17d5c4. Thanks for reporting!

@vitaut vitaut closed this as completed Jul 18, 2020
@ghost
Copy link
Author

ghost commented Jul 24, 2020

Hi vitaut,

Could you please make a patch to 7.0.1 for walking around the issue?.
There are many improvements in version fmt-7.0.x, I do not want to downgrade back to fmt-6.x just to have a small feature.

Thanks.

@vitaut
Copy link
Contributor

vitaut commented Jul 24, 2020

I plan to make another patch release shortly.

@vitaut
Copy link
Contributor

vitaut commented Jul 29, 2020

@ghost
Copy link
Author

ghost commented Jul 29, 2020

Thanks for your effort.
Unfortunately, running the sample (in my first post) with 7.0.2 shows the exact issue existing in 7.0.1.
However the issue does not happen in the "master".

@vitaut
Copy link
Contributor

vitaut commented Jul 30, 2020

As it turned out only half of the issue was fixed in 2b7a146 and incidentally there was another change that made your example work on master. The remaining issue should be fixed in d82fdcc.

@ghost
Copy link
Author

ghost commented Jul 30, 2020

Did you update the fix to tags/7.0.2 or just to "master"? I have not found the way to test your fix.
Also, this issue has not been fixed, should you reopen it?

@vitaut
Copy link
Contributor

vitaut commented Jul 30, 2020

master, releases are not updated retroactively.

@hangdongxue
Copy link

I tried 7.0.3 locale still not working for float number. e.g. if I set language as "italian". when print out decimal point, it prints as "." instead of ","

@vitaut
Copy link
Contributor

vitaut commented Aug 18, 2020

#include <fmt/core.h>
#include <locale>

int main() {
  std::locale::global(std::locale("it_IT.UTF-8"));
  fmt::print("{:L}\n", 4.2);
}

prints

4,2

@hangdongxue
Copy link

I try to print a float number with precision like
fmt::print("{1:.{0}f}", 1, 4.2);
it doesn't print out correct decimal point
it used to work in version 5

@vitaut
Copy link
Contributor

vitaut commented Aug 18, 2020

Please open a separate issue.

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