方法1:
static void CalculateExpression(Args _args)
{
str expr = "(((1+2)*6)/5)";
;
info(num2str(ProdMathEvaluator::evaluate(expr),0,2,1,3));
}
方法2:
static void calculateExpression(Args _args)
{
XppCompiler comp;
str expr;
expr = "(((1+2)*6)/5)";
comp = new XppCompiler();
info(strFmt('%1',comp.compileExpr(expr)));//this validates the expression
info(strFmt('%1',comp.execute(expr)));//this returns the result.
}
方法3:
static void JobEvalBufDemo(Args _args)
{
ExecutePermission perm;
str strCodeToExecute = "(((1+2)*6)/5)";
str strResult;
;
perm = new ExecutePermission();
if (perm != null)
{
// Grants permission to execute the EvalBuf function.
// EvalBuf runs under code access security.
perm.assert();
print "Next will execute the string of code.";
pause; // Click Yes when asked to continue.
strResult = EvalBuf(strCodeToExecute);
// Close the code access permission scope.
CodeAccessPermission::revertAssert();
}
print "strResult is: [", strResult ,"]";
pause;
//
// Expected: "strResult is: [3.6]".
}
转载请注明:ww12345678 的部落格 | AX Helper » How to Calculate Values from a Formula, written in Algebraic Expression, in MS Dynamics Ax 2012
