Slide 53
Slide 53 text
53
© 2012-2021 BASE, Inc.
Go for gomobile (Part)
func Evaluate(formula string) (float64, error) {
expression, err := govaluate.NewEvaluableExpression(formula)
if err != nil {
return 0, err
}
i := make(map[string]interface{})
result, err := expression.Evaluate(i)
if err != nil {
return 0, err
}
v, ok := result.(float64)
if !ok {
return 0, fmt.Error("invalid formula result.”)
}
return v, nil
}