Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.sidhant92.boolparser.datatype;

import java.math.BigDecimal;
import java.util.Optional;
import com.github.sidhant92.boolparser.constant.DataType;

Expand All @@ -22,7 +23,8 @@ public boolean isValid(final Object value) {
boolean isValid = super.defaultIsValid(value);
if (!isValid) {
try {
Integer.parseInt(value.toString());
BigDecimal number = new BigDecimal(value.toString());
Integer.parseInt(number.stripTrailingZeros().toPlainString());
return true;
} catch (Exception ex) {
return false;
Expand All @@ -46,7 +48,8 @@ public Optional<Integer> getValue(Object value) {
return result;
}
try {
return Optional.of(Integer.parseInt(value.toString()));
BigDecimal number = new BigDecimal(value.toString());
return Optional.of(Integer.parseInt(number.stripTrailingZeros().toPlainString()));
} catch (final Exception ignored) {
}
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.sidhant92.boolparser.datatype;

import java.math.BigDecimal;
import java.util.Optional;
import com.github.sidhant92.boolparser.constant.DataType;

Expand All @@ -22,7 +23,8 @@ public boolean isValid(final Object value) {
boolean isValid = super.defaultIsValid(value);
if (!isValid) {
try {
Long.parseLong(value.toString());
BigDecimal number = new BigDecimal(value.toString());
Long.parseLong(number.stripTrailingZeros().toPlainString());
return true;
} catch (Exception ex) {
return false;
Expand All @@ -46,7 +48,8 @@ public Optional<Long> getValue(Object value) {
return result;
}
try {
return Optional.of(Long.parseLong(value.toString()));
BigDecimal number = new BigDecimal(value.toString());
return Optional.of(Long.parseLong(number.stripTrailingZeros().toPlainString()));
} catch (final Exception ignored) {
}
return Optional.empty();
Expand Down