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

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

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.1, 3.3.2
    • Fix Version/s: 3.5
    • Component/s: lang.math.*
    • Labels:
      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

              • Assignee:
                chtompki Rob Tompkins
                Reporter:
                aplatypus will mason
              • Votes:
                1 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: