Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#435 Fix zero with scale to boolean (3.1.x) #438

Merged
merged 2 commits into from
Feb 26, 2024
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
2 changes: 1 addition & 1 deletion src/main/java/com/ezylang/evalex/data/EvaluationValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading