Skip to content

Commit 1ad007d

Browse files
LANG-1806: Allow floating-point suffixes in NumberUtils.isParsableDecimal
1 parent 36e740c commit 1ad007d

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/main/java/org/apache/commons/lang3/math/NumberUtils.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,8 +753,15 @@ private static boolean isParsableDecimal(final String str, final int beginIdx) {
753753
// See https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-NonZeroDigit
754754
int decimalPoints = 0;
755755
boolean asciiNumeric = true;
756+
final int lastIndex = str.length() - 1;
757+
756758
for (int i = beginIdx; i < str.length(); i++) {
757759
final char ch = str.charAt(i);
760+
761+
if(i == lastIndex && (ch == 'f' || ch == 'F' || ch == 'd' || ch == 'D')){
762+
return true;
763+
}
764+
758765
final boolean isDecimalPoint = ch == '.';
759766
if (isDecimalPoint) {
760767
decimalPoints++;

src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,8 +1028,8 @@ void testIsParsable() {
10281028
assertTrue(NumberUtils.isParsable("-018.2"));
10291029
assertTrue(NumberUtils.isParsable("-.236"));
10301030
assertTrue(NumberUtils.isParsable("2."));
1031-
// TODO assertTrue(NumberUtils.isParsable("2.f"));
1032-
// TODO assertTrue(NumberUtils.isParsable("2.d"));
1031+
assertTrue(NumberUtils.isParsable("2.f"));
1032+
assertTrue(NumberUtils.isParsable("2.d"));
10331033
}
10341034

10351035
/**

0 commit comments

Comments
 (0)