You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Rob Tompkins (JIRA)" <ji...@apache.org> on 2016/07/28 11:01:20 UTC

[jira] [Commented] (LANG-1038) NumberUtils#isNumber() returns false for "+2" and true for "-2"

    [ https://issues.apache.org/jira/browse/LANG-1038?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15397393#comment-15397393 ] 

Rob Tompkins commented on LANG-1038:
------------------------------------

There seems to be clear inconsistency between {{NumberUtils.createNumber(final String val)}} and {{NumberUtils.isNumber(final String str)}}. I agree here that the javadoc should be clarified as to what {{isNumber}} should return, but either way there should be consistency.

> NumberUtils#isNumber() returns false for "+2" and true for "-2"
> ---------------------------------------------------------------
>
>                 Key: LANG-1038
>                 URL: https://issues.apache.org/jira/browse/LANG-1038
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.math.*
>    Affects Versions: 3.1, 3.3.2
>            Reporter: will mason
>             Fix For: Discussion
>
>
> 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:
> {code:java}
> NumberUtils.isNumber( wrkStr.replaceFirst( "\\+", "") )
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)