Search in sources :

Example 1 with DecimalCoreInstance

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);
}
Also used : DecimalCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.DecimalCoreInstance) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) FloatCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.FloatCoreInstance) IntegerCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.IntegerCoreInstance) IntegerCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.IntegerCoreInstance) DecimalCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.DecimalCoreInstance) BigDecimal(java.math.BigDecimal)

Aggregations

BigDecimal (java.math.BigDecimal)1 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)1 DecimalCoreInstance (org.finos.legend.pure.m4.coreinstance.primitive.DecimalCoreInstance)1 FloatCoreInstance (org.finos.legend.pure.m4.coreinstance.primitive.FloatCoreInstance)1 IntegerCoreInstance (org.finos.legend.pure.m4.coreinstance.primitive.IntegerCoreInstance)1