D365/AX7:EvalBuf() Alternative & Replacement – Evaluate complex algebraic expressions

Purpose

Calculate & evaluate complex algebraic expressions given in a string.

For example

str expression = “((12 + 2/2)*2)-6”;

After calculation above expression, result should come 20.

Issue

In Microsoft dynamics AX 2012,  EvalBuf() function was available for calculating complex algebraic expression.But in D365 finance and operation the function evalBuf() is missing and you cannot use it anymore.

Solution with sample code

We can use ProdMathEvaluator::evaluate() instead of EvalBuf().

[code language = “cpp”]
str expression = “((12 + 2/2)*2)-6”;
info(strFmt(‘%1’, ProdMathEvaluator::evaluate(expression)));
[/code]

Note

The expression string should not comma separator “,” etc otherwise you will get below error

“Misuse of “Our expression”, Please review the elements and symbols used in the equation.”

[code language = “cpp”]
str expression = “((12 + 2/2)*2)-6”;
expression = strRem(expression, “,”); // removing comma
info(strFmt(‘%1’, ProdMathEvaluator::evaluate(expression)));
[/code]

 

cheers 🙂

piyush adhikari

Leave a Reply