Skip to content

Commit 1890a67

Browse files
authored
Merge pull request #37 from sidhant92/array_math_functions
handle decimal with 0 fractional
2 parents 4dce460 + 19a3756 commit 1890a67

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/main/java/com/github/sidhant92/boolparser/datatype/IntegerDataType.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.sidhant92.boolparser.datatype;
22

3+
import java.math.BigDecimal;
34
import java.util.Optional;
45
import com.github.sidhant92.boolparser.constant.DataType;
56

@@ -22,7 +23,8 @@ public boolean isValid(final Object value) {
2223
boolean isValid = super.defaultIsValid(value);
2324
if (!isValid) {
2425
try {
25-
Integer.parseInt(value.toString());
26+
BigDecimal number = new BigDecimal(value.toString());
27+
Integer.parseInt(number.stripTrailingZeros().toPlainString());
2628
return true;
2729
} catch (Exception ex) {
2830
return false;
@@ -46,7 +48,8 @@ public Optional<Integer> getValue(Object value) {
4648
return result;
4749
}
4850
try {
49-
return Optional.of(Integer.parseInt(value.toString()));
51+
BigDecimal number = new BigDecimal(value.toString());
52+
return Optional.of(Integer.parseInt(number.stripTrailingZeros().toPlainString()));
5053
} catch (final Exception ignored) {
5154
}
5255
return Optional.empty();

src/main/java/com/github/sidhant92/boolparser/datatype/LongDataType.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.sidhant92.boolparser.datatype;
22

3+
import java.math.BigDecimal;
34
import java.util.Optional;
45
import com.github.sidhant92.boolparser.constant.DataType;
56

@@ -22,7 +23,8 @@ public boolean isValid(final Object value) {
2223
boolean isValid = super.defaultIsValid(value);
2324
if (!isValid) {
2425
try {
25-
Long.parseLong(value.toString());
26+
BigDecimal number = new BigDecimal(value.toString());
27+
Long.parseLong(number.stripTrailingZeros().toPlainString());
2628
return true;
2729
} catch (Exception ex) {
2830
return false;
@@ -46,7 +48,8 @@ public Optional<Long> getValue(Object value) {
4648
return result;
4749
}
4850
try {
49-
return Optional.of(Long.parseLong(value.toString()));
51+
BigDecimal number = new BigDecimal(value.toString());
52+
return Optional.of(Long.parseLong(number.stripTrailingZeros().toPlainString()));
5053
} catch (final Exception ignored) {
5154
}
5255
return Optional.empty();

0 commit comments

Comments
 (0)