use of org.finos.legend.pure.m4.coreinstance.primitive.DecimalCoreInstance in project legend-pure by finos.
the class RoundWithScale method execute.
@Override
public CoreInstance execute(ListIterable<? extends CoreInstance> params, Stack<MutableMap<String, CoreInstance>> resolvedTypeParameters, Stack<MutableMap<String, CoreInstance>> resolvedMultiplicityParameters, VariableContext variableContext, CoreInstance functionExpressionToUseInStack, Profiler profiler, InstantiationContext instantiationContext, ExecutionSupport executionSupport, Context context, ProcessorSupport processorSupport) throws PureExecutionException {
CoreInstance number = Instance.getValueForMetaPropertyToOneResolved(params.get(0), M3Properties.values, processorSupport);
CoreInstance scale = Instance.getValueForMetaPropertyToOneResolved(params.get(1), M3Properties.values, processorSupport);
BigDecimal decimal = number instanceof DecimalCoreInstance ? ((DecimalCoreInstance) number).getValue() : ((FloatCoreInstance) number).getValue();
BigDecimal result = decimal.setScale(((IntegerCoreInstance) scale).getValue().intValue(), RoundingMode.HALF_UP);
return NumericUtilities.toPureNumberValueExpression(result, number instanceof DecimalCoreInstance, this.repository, processorSupport);
}
Aggregations