Skip to content
Open
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
Expand Up @@ -134,12 +134,8 @@ protected static void preProcessInputVariables(DecisionTable decisionTable, Map<
} else if (inputVariableValue instanceof Long || inputVariableValue instanceof Integer) {
BigInteger transformedNumber = new BigInteger(inputVariableValue.toString());
inputVariables.put(inputVariableName, transformedNumber);
} else if (inputVariableValue instanceof Double ) {
BigDecimal transformedNumber = new BigDecimal((Double) inputVariableValue);
inputVariables.put(inputVariableName, transformedNumber);
} else if (inputVariableValue instanceof Float) {
double doubleValue = Double.parseDouble(inputVariableValue.toString());
BigDecimal transformedNumber = new BigDecimal(doubleValue);
} else if (inputVariableValue instanceof Double || inputVariableValue instanceof Float) {
BigDecimal transformedNumber = new BigDecimal(inputVariableValue.toString());
inputVariables.put(inputVariableName, transformedNumber);
}
} catch (Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.flowable.dmn.engine.impl.el;

import static org.assertj.core.api.Assertions.assertThat;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import org.flowable.dmn.model.DecisionTable;
import org.junit.jupiter.api.Test;

public class ELExecutionContextBuilderTest {

@Test
public void shouldPreserveDoubleInputPrecision() {
Map<String, Object> inputVariables = new HashMap<>();
inputVariables.put("input", 0.1D);

ELExecutionContextBuilder.preProcessInputVariables(new DecisionTable(), inputVariables, null);

assertThat(inputVariables).containsEntry("input", new BigDecimal("0.1"));
}

@Test
public void shouldPreserveFloatInputPrecision() {
Map<String, Object> inputVariables = new HashMap<>();
inputVariables.put("input", 0.1F);

ELExecutionContextBuilder.preProcessInputVariables(new DecisionTable(), inputVariables, null);

assertThat(inputVariables).containsEntry("input", new BigDecimal("0.1"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ protected BigDecimal coerceToBigDecimal(Object value) {
if (value instanceof BigInteger) {
return new BigDecimal((BigInteger)value);
}
if (value instanceof Double || value instanceof Float) {
double doubleValue = ((Number)value).doubleValue();
if (doubleValue != Math.rint(doubleValue)) {
return new BigDecimal(value.toString());
}
}
if (value instanceof Number) {
return new BigDecimal(((Number)value).doubleValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ void testToBigDecimal() {
assertThat(converter.coerceToBigDecimal(99L)).isEqualTo(ninetynine);
assertThat(converter.coerceToBigDecimal(99F)).isEqualTo(ninetynine);
assertThat(converter.coerceToBigDecimal(99.0)).isEqualTo(ninetynine);
assertThat(converter.coerceToBigDecimal(0.1F)).isEqualTo(new BigDecimal("0.1"));
assertThat(converter.coerceToBigDecimal(0.1D)).isEqualTo(new BigDecimal("0.1"));
assertThat(converter.coerceToBigDecimal(new BigDecimal(99))).isEqualTo(ninetynine);
assertThat(converter.coerceToBigDecimal(new BigInteger("99"))).isEqualTo(ninetynine);
assertThat(converter.coerceToBigDecimal(ninetynine.toString())).isEqualTo(ninetynine);
Expand Down