You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For this type of operation, you may need to configure the locale of the expression resolver.
Here I did something like this:
using Flee.PublicTypes;publicclassDynamicExpressions{privatereadonlyExpressionContextexpressionContext=new();publicDynamicExpressions(){// Inclusion of System.Math, to allow the use of all its methods
expressionContext.Imports.AddType(typeof(Math),"Math");// Regionality settings
expressionContext.ParserOptions.DecimalSeparator ='.';
expressionContext.ParserOptions.FunctionArgumentSeparator =',';
expressionContext.ParserOptions.RecreateParser();}/// <summary>/// Receives a boolean expression in string format and returns the result/// <Examples: "(10.90 - 5.0 < 0.0)", "("123" <> "")"/// </summary>/// <param name="expression"></param>/// <returns></returns>publicboolEvaluateBoolExpression(stringexpression){boolresult;try{IGenericExpression<bool>e= expressionContext.CompileGeneric<bool>(expression);result= e.Evaluate();}catch(Exceptionex){thrownew Exception("Erro ao validar a expressão booleana: ("+expression+") - '"+ ex.Message +"'");}returnresult;}// Example of using a System.Math method// double valorArredondado = expressionContext.CompileGeneric<double>("Math.Round(1.55540040, 2)").Evaluate();publicdoubleEvaluateDoubleExpression(stringexpression){doubleresult;tryIGenericExpression<double>e= expressionContext.CompileGeneric<double>(expression);result= e.Evaluate();}catch(Exceptionex){thrownew Exception("Error validating mathematical expression: ("+expression+") - '"+ ex.Message +"'");}returnresult;}}
Is it possible to use decimal type in a boolean expression such as:: "myDecVar >= 10.0" ?
If MyDecVar is something like 3.1, flee throws an error, saying:
"Error: CompareElement: Operation 'GreaterThanOrEqual' is not defined for types 'Decimal' and 'Double'"
Same for GreaterThan and Equals.
Works fine with integers.
Is there a way to use decimals this way in flee, or should I just convert to decimals.
Thanks
Jonathan
The text was updated successfully, but these errors were encountered: