You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
usingJ2N.Numerics;usingSystem.Globalization;varsv=CultureInfo.GetCultureInfo("sv-FI");vard=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.
The text was updated successfully, but these errors were encountered:
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
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
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.Note that this works with cultures with
"-"
(int value 45) as the NegativeSign, such as en-US.The text was updated successfully, but these errors were encountered: