[
https://issues.apache.org/jira/browse/LANG-1038?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14147054#comment-14147054
]
will mason commented on LANG-1038:
----------------------------------
Documentation notwithstanding, there are two cogent pro points to keep in mind:
1. In Java: int i = Integer.parseInt("+2"), produces: int = 2
2. In mathematics: +2 is a number.
Also, for consistency, if isNumber("-1") is true, a leading plus sign will be
expected to be valid by end-users (not programmers). A typical use case for
isNumber() is to verify input from a device, file or user input -- I submit
that isNumber ought support syntax recognised by parser functions such as,
Integer.parseInt().
The point of discussion should be about user accessibility, serviceability &
maintainability of client code and accepted arithmetic notation.
> 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)