File tree Expand file tree Collapse file tree
src/main/java/com/github/sidhant92/boolparser/datatype Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package com .github .sidhant92 .boolparser .datatype ;
22
3+ import java .math .BigDecimal ;
34import java .util .Optional ;
45import 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 ();
Original file line number Diff line number Diff line change 11package com .github .sidhant92 .boolparser .datatype ;
22
3+ import java .math .BigDecimal ;
34import java .util .Optional ;
45import 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 ();
You can’t perform that action at this time.
0 commit comments