LANG-1016: NumberUtils#isParsable method(s). Apply Juan PabloSantos Rodríguez patch for handling negative numbers.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1609898 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
673dbc5794
commit
6240a05c12
|
@ -1488,7 +1488,11 @@ public class NumberUtils {
|
|||
if( StringUtils.endsWith( str, "." ) ) {
|
||||
return false;
|
||||
}
|
||||
return isDigits( StringUtils.replaceOnce( str, ".", StringUtils.EMPTY ) );
|
||||
if( StringUtils.startsWith( str, "-" ) ) {
|
||||
return isDigits( StringUtils.replaceOnce( StringUtils.substring( str, 1 ), ".", StringUtils.EMPTY ) );
|
||||
} else {
|
||||
return isDigits( StringUtils.replaceOnce( str, ".", StringUtils.EMPTY ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1268,7 +1268,12 @@ public class NumberUtilsTest {
|
|||
assertFalse( NumberUtils.isParsable("64L") );
|
||||
assertTrue( NumberUtils.isParsable("64.2") );
|
||||
assertTrue( NumberUtils.isParsable("64") );
|
||||
assertTrue(NumberUtils.isParsable("018"));
|
||||
assertTrue( NumberUtils.isParsable("018") );
|
||||
assertTrue( NumberUtils.isParsable(".18") );
|
||||
assertTrue( NumberUtils.isParsable("-65") );
|
||||
assertTrue( NumberUtils.isParsable("-018") );
|
||||
assertTrue( NumberUtils.isParsable("-018.2") );
|
||||
assertTrue( NumberUtils.isParsable("-.236") );
|
||||
}
|
||||
|
||||
private boolean checkCreateNumber(final String val) {
|
||||
|
|
Loading…
Reference in New Issue