Math expression evaluator API

Evaluate math expressions safely: units (5 cm to inch), matrices, statistics, variables, big numbers or exact fractions, with formatted result and LaTeX.

GETPOSThttps://apibox.io.vn/v1/math-eval
Developer utilities▶ Try it online

Send an expression in expr (GET or POST) or a batch in expressions (up to 100, sharing variables: a = 5, then a * 2). The evaluator is mathjs with a restricted function set: arithmetic, powers and roots, logarithms, rounding, trigonometry, gcd / lcm, factorial and combinations, statistics (mean, median, std, variance, quantile…), matrices (det, inv, transpose, dot, cross), comparisons and logic, complex numbers, constants and units with conversion (100 km/h to m/s, 5 cm + 2 inch to mm, 10 kg * 9.81 m/s^2 to N). You can define functions (f(x) = x^2 + 1) and pass variables in scope (numbers, arrays or strings such as "42 km").

number=bignumber computes with 64 significant digits (precision 16–256), number=fraction gives exact fractions (1/3 + 1/6 → 1/2). Each result comes as a formatted string (digits significant digits, 15 by default), a JSON value, its type and the LaTeX of the expression for display.

Safety: import, createUnit, evaluate, parse, simplify, derivative and other meta functions are disabled, property access to constructors is blocked by mathjs, expressions are limited to 2,000 characters, matrices and ranges to 100,000 elements, factorial to 100,000 and exact powers to exponent 10,000; a batch stops after 2 seconds.

Parameters

NameInTypeRequiredDefault
exprquery|bodystringnoOne expression (max 2,000 characters).
expressionsbodyarraynoBatch of expressions evaluated in order with shared variables (max 100).
scopebodyobjectnoVariables: {"price": 120000, "d": "42 km"}.
numberquery|bodystringnonumbernumber (double), bignumber or fraction.
precisionquery|bodynumberno64Significant digits of bignumber mode (16–256).
digitsquery|bodynumberno15Significant digits of the formatted result.

Example

curl "https://apibox.io.vn/v1/math-eval?expr=5%20cm%20%2B%202%20inch%20to%20mm" \
  -H "Authorization: Bearer YOUR_API_KEY"

Response

{
  "expression": "5 cm + 2 inch to mm",
  "result": "100.8 mm",
  "value": {
    "value": 100.8,
    "unit": "mm"
  },
  "type": "Unit",
  "tex": "5~\\mathrm{cm}+2~\\mathrm{inch}\\rightarrow\\mathrm{mm}",
  "number": "number",
  "ms": 6
}

Use cases

  • Let users type price or discount formulas in your app
  • Convert units in a chat bot or a spreadsheet import
  • Compute exact fractions or 64-digit results
  • Render formulas as LaTeX next to their result

FAQ

Why does 0.1 + 0.2 show 0.3?

The formatted result uses 15 significant digits; value keeps the raw double (0.30000000000000004). Use number=bignumber for exact decimal arithmetic.

Can expressions run code?

No: only math functions are available, meta functions such as import or evaluate are disabled and JavaScript properties cannot be reached.

Which units are supported?

All built-in mathjs units: length, mass, time, speed, area, volume, temperature, force, energy, power, pressure, data (bit, byte) and SI prefixes. Currencies are not included.

Related APIs

Start with 1,000 free requests every month. Get free API key →