Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1038

NumberUtils#isNumber() returns false for "+2" and true for "-2"

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.1, 3.3.2
    • 3.5
    • lang.math.*
    • None

    Description

      The strings "+2" and "+ 2" give a "False" result when tested by isNumber().

      Case one, "+2" is legal with Integer.parseInt(). Case two: "+ 2" gives an exception with Integer.parseInt().

      I believe the function should match legitimate inputs for the respective parser function depending on the number type.

      Workaround: Use something like:

      NumberUtils.isNumber( wrkStr.replaceFirst( "\\+", "") )
      

      Attachments

        Issue Links

          Activity

            People

              chtompki Rob Tompkins
              aplatypus aplatypus
              Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: