diff --git a/src/main/java/com/ezylang/evalex/data/EvaluationValue.java b/src/main/java/com/ezylang/evalex/data/EvaluationValue.java index 0985d407..9bb0dffe 100644 --- a/src/main/java/com/ezylang/evalex/data/EvaluationValue.java +++ b/src/main/java/com/ezylang/evalex/data/EvaluationValue.java @@ -374,7 +374,7 @@ public String getStringValue() { public Boolean getBooleanValue() { switch (getDataType()) { case NUMBER: - return !value.equals(BigDecimal.ZERO); + return getNumberValue().compareTo(BigDecimal.ZERO) != 0; case BOOLEAN: return (Boolean) value; case STRING: diff --git a/src/test/java/com/ezylang/evalex/data/conversion/BooleanConverterTest.java b/src/test/java/com/ezylang/evalex/data/conversion/BooleanConverterTest.java index 4266b906..a2d3c1fa 100644 --- a/src/test/java/com/ezylang/evalex/data/conversion/BooleanConverterTest.java +++ b/src/test/java/com/ezylang/evalex/data/conversion/BooleanConverterTest.java @@ -56,4 +56,11 @@ void testCanNotConvert() { assertThat(converter.canConvert("true")).isFalse(); assertThat(converter.canConvert(new BigDecimal(1))).isFalse(); } + + @Test + void testNumberToBoolean() { + EvaluationValue value = EvaluationValue.numberValue(new BigDecimal("0.0")); + + assertThat(value.getBooleanValue()).isFalse(); + } } diff --git a/src/test/java/com/ezylang/evalex/operators/booleans/InfixAndOperatorTest.java b/src/test/java/com/ezylang/evalex/operators/booleans/InfixAndOperatorTest.java index 7e926ec8..1b0e16ff 100644 --- a/src/test/java/com/ezylang/evalex/operators/booleans/InfixAndOperatorTest.java +++ b/src/test/java/com/ezylang/evalex/operators/booleans/InfixAndOperatorTest.java @@ -30,6 +30,7 @@ class InfixAndOperatorTest extends BaseEvaluationTest { "1&&1 : true", "1&&2 : true", "0&&1 : false", + "0.0&&1 : false", "22&&33 : true", "\"true\"&&\"true\" : true", "\"true\"&&\"false\" : false", diff --git a/src/test/java/com/ezylang/evalex/operators/booleans/InfixOrOperatorTest.java b/src/test/java/com/ezylang/evalex/operators/booleans/InfixOrOperatorTest.java index 365df6e7..c8977a1e 100644 --- a/src/test/java/com/ezylang/evalex/operators/booleans/InfixOrOperatorTest.java +++ b/src/test/java/com/ezylang/evalex/operators/booleans/InfixOrOperatorTest.java @@ -30,7 +30,9 @@ class InfixOrOperatorTest extends BaseEvaluationTest { "1||1 : true", "1||2 : true", "0||1 : true", + "0.0||1.0 : true", "0||0 : false", + "0.0||0.0 : false", "22||33 : true", "\"true\"||\"true\" : true", "\"true\"||\"false\" : true",