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
{{ message }}
Repository navigation
double.TryParse of "0,12" incorrectly returns true with result of 0.12. #25868
When executing the following the return value is true (parsing succeeded) and the number value becomes 0.12:
double.TryParse("0,12", NumberStyles.Number, CultureInfo.GetCultureInfo("en-US"), out number)
The input is not a valid US number since the comma proceeded by a zero and followed by only 2 digits. US numbers with a comma are only valid if the integer part is a 1 to 3 digits (but not a sequence of zero digits) followed by zero or more groups of 3 digits separated by commas.
VisualStudio 2015 Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.7.02556
Build for x64 and .Net 4.5
The bug is that it is not failing. As I wrote, "0,12" is not a valid number
in the US. It would only produce 0.12 in a culture which uses periods (.)
for the thousand separator and the comma as the decimal point.
The proper behavior is for this call to return false.
Sorry, no. The only difference between NumberStyles.Number and
NumberStyles.Float is that Number allows trailing sign and thousands while
Float allows exponent. Number should not recognize "0,12" in a culture
using commas as the thousands separator, but should recognize it in a
culture using the comma as a decimal point. No matter what combination of
NumberStyles are used "0,12" is not a valid number when using a culture
which does not use the comma as a decimal point.
If NumberStyles.Number is ignoring non-digit characters this is wrong since
is is a composite format allowing leading signs, trailing signs, thousands
separators and decimal points.
The current and historical behavior is to return 12 which is expected since NumberStyles.Number includes NumberStyles.AllowThousands and so , is effectively ignored as the "group separator" for integral digits.
Activity
nil4 commentedon Apr 13, 2018
@DonaldRich do you see different results if you change
CultureInfo.GetCultureInfo("en-US")tonew CultureInfo("en-US", useUserOverride: false)?DonaldRich commentedon Apr 13, 2018
DonaldRich commentedon Apr 13, 2018
mazong1123 commentedon Apr 18, 2018
Sounds like a bug. @stephentoub @jkotas do we have any historical reason for missing this validation?
tannergooding commentedon Jul 9, 2025
The current and historical behavior is to return
12which is expected sinceNumberStyles.NumberincludesNumberStyles.AllowThousandsand so,is effectively ignored as the "group separator" for integral digits.