Skip to content

Commit 755263e

Browse files
LANG-1806: Allow floating-point suffixes in NumberUtils.isParsableDecimal
1 parent 0337e59 commit 755263e

2 files changed

Lines changed: 11 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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,12 +1028,14 @@ 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+
1032+
assertTrue(NumberUtils.isParsable("2.f"));
1033+
assertTrue(NumberUtils.isParsable("2.d"));
10331034
// Float.parseFloat("1.2e-5f")
10341035
// TODO assertTrue(NumberUtils.isParsable("1.2e-5f"));
10351036
// Double.parseDouble("1.2e-5d")
10361037
// TODO assertTrue(NumberUtils.isParsable("1.2e-5d"));
1038+
10371039
}
10381040

10391041
/**

0 commit comments

Comments
 (0)