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

MatrixIO.printJava should ignore default locale #161

Closed
HGuillemet opened this issue Nov 21, 2022 · 7 comments
Closed

MatrixIO.printJava should ignore default locale #161

HGuillemet opened this issue Nov 21, 2022 · 7 comments
Assignees

Comments

@HGuillemet
Copy link

MatrixIO.printJava formats numbers using PrintStream.printf(format, x).
So if our default locale uses a comma for decimal separator, we end up with numbers not conforming to Java.
printf has an overload taking an explicit locale. I guess it's the one to use, specifying Locale.US or similar.

@lessthanoptimal
Copy link
Owner

@HGuillemet so is the issue that it's conforming to your locale or the issue that it is not conforming to your locale?

Either way, what I think you're requesting is a function like this:

public static void print( PrintStream out, DMatrix mat, Local local, String format )
correct?

@ennerf
Copy link
Contributor

ennerf commented Nov 25, 2022

Likely that it is conforming to the locale. I've run into this a few times on German systems that would print numbers in a format that Java fails to parse later on.

@HGuillemet
Copy link
Author

HGuillemet commented Nov 25, 2022

Right. printJava conforms to my locale but it should not.
No need for a new function. printJava should be modified to ignore default locale (and use Locale.US for instance, or, probably better, the plain Double.toString/Float.toString methods that will print all decimals).
I'd say it's a bug, not a feature request.

@lessthanoptimal
Copy link
Owner

Just pushed the change to make it default to US. There's a static variable that you can change to change the local.

@lessthanoptimal
Copy link
Owner

FYI This fix is going to be released in 0.41.1

@HGuillemet
Copy link
Author

HGuillemet commented Dec 5, 2022

Thank you for this fix.
I would probably have limited the fix to printJava.
For other output methods, which generate human-readable data, It is normal to use the system default locale so that the comma character, but also for instance the thousand separator, correspond to what the local humans use.
Only printJava (and saveMatlab of course) generate data for machines which must conform to a standard.

Also you'll break more existing codes.

@lessthanoptimal
Copy link
Owner

I was considering that but decided to go for it being universally compatible by default. This way pasted output can be used by everyone. Doesn't seem to be any really clean option here. I guess I'll see if people complain. Now the JavaDoc should mention that static variable, which it currently doesnt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants