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

Round-trip Double ToString/Parse failure with some cultures and exponential notation #128

Open
paulirwin opened this issue Dec 28, 2024 · 1 comment · May be fixed by #129
Open

Round-trip Double ToString/Parse failure with some cultures and exponential notation #128

paulirwin opened this issue Dec 28, 2024 · 1 comment · May be fixed by #129
Assignees
Labels
is:bug Something isn't working

Comments

@paulirwin
Copy link
Collaborator

paulirwin commented Dec 28, 2024

Found via random test in Lucene.NET. J2N.Numerics.Double has a round-trip failure parsing its own output for cultures with Unicode minus sign as its NegativeSign and exponential notation values where the exponent is negative.

using J2N.Numerics;
using System.Globalization;

var sv = CultureInfo.GetCultureInfo("sv-FI");
var d = 6.815791e-4d;

Console.WriteLine(Double.ToString(d, sv)); // prints: "6,815791E-4"
Double.Parse(Double.ToString(d, sv), sv); // fails with FormatException: "Input string was not in a correct format. Value: '6,815791E-4'."

Note that this works with cultures with "-" (int value 45) as the NegativeSign, such as en-US.

@paulirwin
Copy link
Collaborator Author

Found the root cause, investigating a possible solution. The sv-FI culture has as its NegativeSign the character with integer value 8722, which is a Unicode minus sign, but the formatted string uses the regular '-' character for the exponent, which is integer value 45. Because of this mismatch, it does not parse the exponent correctly and fails. I am guessing it's just neglecting to use the NegativeSign for the exponent formatting.

@paulirwin paulirwin changed the title Round-trip Double ToString/Parse failure with decimal comma and exponential notation Round-trip Double ToString/Parse failure with some cultures and exponential notation Dec 31, 2024
paulirwin added a commit to paulirwin/J2N that referenced this issue Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant