Skip to content

double.TryParse of "0,12" incorrectly returns true with result of 0.12. #25868

Closed as not planned

Description

@DonaldRich

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

Installed Version: Community

Activity

  1. nil4 commented on Apr 13, 2018

    @nil4
    Contributor

    @DonaldRich do you see different results if you change CultureInfo.GetCultureInfo("en-US") to new CultureInfo("en-US", useUserOverride: false)?

  2. DonaldRich commented on Apr 13, 2018

    @DonaldRich
    Author
  3. DonaldRich commented on Apr 13, 2018

    @DonaldRich
    Author
  4. mazong1123 commented on Apr 18, 2018

    @mazong1123
    Contributor

    Sounds like a bug. @stephentoub @jkotas do we have any historical reason for missing this validation?

  5. transferred this issue fromdotnet/corefxon Jan 31, 2020
  6. added this to the Future milestone on Jan 31, 2020
  7. added
    untriaged
    on Feb 23, 2020
  8. added and removed
    untriaged
    on Jun 23, 2020
  9. added
    needs-further-triage
    on Jan 15, 2021
  10. removed
    needs-further-triage
    on Nov 10, 2024
  11. tannergooding commented on Jul 9, 2025

    @tannergooding
    Member

    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.

  12. locked and limited conversation to collaborators on Aug 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions