controladdin function

weneedweneed Member Posts: 82
I need to convert a string representing a numeric expression into its corresponding result. In the same way by when in an excel cell you enter "2+2*4" and the result is 10.
EVALUATE Function not work. Need for a 'numerical' string and does not calculate expressions and I cannot use DLL.
Cannot find a solution.
I had thought of using a javascript function like this by inserting it in a controlladdin:

function convert(expression){
return eval(expression);
}

It's possible use the function in a codeunit procedure?
Someone can show me an example?
Are there better solutions?



Answers

  • JJMcJJMc Member Posts: 60
    Why don't you use an API?

    i.e.:

    curl --location 'http://api.mathjs.org/v4/' \
    --header 'Content-Type: application/json' \
    --data '{
    "expr": "a = 1.2 * (2 + 4.55)","precision": 20
    }'
  • weneedweneed Member Posts: 82
    JJMc wrote: »
    Why don't you use an API?

    i.e.:

    curl --location 'http://api.mathjs.org/v4/' \
    --header 'Content-Type: application/json' \
    --data '{
    "expr": "a = 1.2 * (2 + 4.55)","precision": 20
    }'

    HiJJMc,

    I believe it is not a good idea to use a free service in production. If for some reason it is no longer available?
  • AlexDenAlexDen Member Posts: 86
    You can try something like this:
    CalcMathExpression(Expression : Text) Result : Decimal
    VAR
    DataTable : DotNet System.Data.DataTable.'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    BEGIN
    DataTable := DataTable.DataTable;
    Result := DataTable.Compute(Expression,'');
    END;
    
  • weneedweneed Member Posts: 82
    AlexDen wrote: »
    You can try something like this:
    CalcMathExpression(Expression : Text) Result : Decimal
    VAR
    DataTable : DotNet System.Data.DataTable.'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    BEGIN
    DataTable := DataTable.DataTable;
    Result := DataTable.Compute(Expression,'');
    END;
    

    Hi AlexDen,

    dotnet is not an option on cloud
Sign In or Register to comment.