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:
Benedikt Ritter 2014-07-12 09:48:13 +00:00
parent 673dbc5794
commit 6240a05c12
2 changed files with 11 additions and 2 deletions

View File

@ -1488,7 +1488,11 @@ public class NumberUtils {
if( StringUtils.endsWith( str, "." ) ) {
return false;
}
if( StringUtils.startsWith( str, "-" ) ) {
return isDigits( StringUtils.replaceOnce( StringUtils.substring( str, 1 ), ".", StringUtils.EMPTY ) );
} else {
return isDigits( StringUtils.replaceOnce( str, ".", StringUtils.EMPTY ) );
}
}
}

View File

@ -1269,6 +1269,11 @@ public class NumberUtilsTest {
assertTrue( NumberUtils.isParsable("64.2") );
assertTrue( NumberUtils.isParsable("64") );
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) {