Skip to content

Commit

Permalink
Merge pull request #37 from sidhant92/array_math_functions
Browse files Browse the repository at this point in the history
handle decimal with 0 fractional
  • Loading branch information
sidhant92 authored Jun 10, 2024
2 parents 4dce460 + 19a3756 commit 1890a67
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
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

0 comments on commit 1890a67

Please sign in to comment.