Skip to content

Calculator

The Calculator component lets you type a mathematical expression as plain text and instantly see the result. It works entirely inside Nappai, so you don’t need to connect to any external service.

How it Works

When you enter an expression such as 4*4*(33/22)+12-20, the component parses the text, checks that only simple operators (+, -, *, /, **) are used, evaluates the expression, and returns the numeric result. If the expression is malformed or causes an error (for example, division by zero), the component returns a clear error message instead of crashing.

Inputs

  • Expression: The arithmetic expression to evaluate (e.g., '4*4*(33/22)+12-20').

Outputs

  • Data: A Data object that contains either the calculated result (result) or an error message (error) along with the original input.
  • Tool: A reusable tool that can be called by other components or by the LLM to evaluate expressions on demand.

Usage Example

  1. Add the Calculator component to your workflow.
  2. Set the Expression field to 12/4 + 3*2.
  3. Run the workflow.
  4. The component outputs a Data object with result: 9.
  5. You can feed this result into a subsequent component, such as a Number Formatter or a Data Aggregator, to continue building your automation.
  • Number Formatter – Format numeric results for display or export.
  • Data Aggregator – Combine multiple numeric values into sums, averages, etc.
  • Text Input – Capture user-provided text that can be passed to the Calculator.

Tips and Best Practices

  • Use parentheses to control the order of operations, e.g., 2*(3+4).
  • Keep expressions simple; the Calculator does not support functions like sqrt() or sin().
  • Test expressions with small numbers first to verify correctness before using them in larger workflows.
  • If you need to handle more complex math, consider chaining multiple Calculator components or using a dedicated math library component.

Security Considerations

The Calculator evaluates only basic arithmetic expressions and does not execute arbitrary code or call external services. It safely rejects function calls and unsupported operations, so it is safe to use with user‑supplied input.