Options

controladdin function

weneedweneed Member Posts: 81
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

  • Options
    JJMcJJMc Member Posts: 59
    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
    }'
  • Options
    weneedweneed Member Posts: 81
    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?
  • Options
    AlexDenAlexDen Member Posts: 85
    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;
    
  • Options
    weneedweneed Member Posts: 81
    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.