What is a math expression evaluator?
A math expression evaluator reads a formula the way you would write it on paper and returns the answer. Where a button calculator makes you enter one operation at a time, here you type or paste the whole expression, such as 2*sqrt(6) + 10 / 4, and the result updates as you type. It is built on the math.js expression parser, which understands far more than basic arithmetic: functions (sqrt, sin, log, round), constants (pi, e), variables, units, matrices and complex numbers.
That makes it useful for engineers, students and developers who need a scratchpad rather than a keypad. You can convert units inside a formula (5 cm to inch), define variables on separate lines and reuse them (a = 3, b = 4, sqrt(a^2 + b^2)), compute a matrix determinant (det([1,2;3,4])) or check a formula before putting it in code. Multi-line input is evaluated line by line and the lines share their variables, so a mistake on one line is reported on that line and does not stop the others.
You choose how the answer is displayed: the number of significant digits (14 by default, which hides floating-point noise such as 0.30000000000000004) and the notation, either automatic, fixed, exponential or engineering. Everything is calculated in your browser, and expressions longer than 5,000 characters are refused so the page stays responsive. For a click-and-type calculator with history and percentages, use the calculator.
How to evaluate an expression
- Type or paste your expression in the box. The page opens with an example so you can see the result immediately.
- Read the result below the input. It updates as you type, after a very short pause.
- For several calculations, write one per line. Variables defined on a line are available on the lines below.
- Set the precision (significant digits) and the notation if you need a specific format, for example exponential for very large or small numbers.
- If the expression cannot be calculated, read the message: it names the problem reported by the parser. Check parentheses, operators and function names.
- Copy the result or all results.
Examples
The default expression
2*sqrt(6) + 10 / 4 gives 7.3989794855664.
Units
5 cm to inch gives 1.9685039370079 inch, 12.7 mm to inch gives 0.5 inch and 10 km/h to m/s gives 2.7777777777778 m / s.
Variables on several lines
a = 3
b = 4
sqrt(a^2 + b^2)The three lines give 3, 4 and 5, the length of the hypotenuse of a 3-4-5 triangle.
Matrices and complex numbers
det([1,2;3,4]) is -2, and sqrt(-4) is the complex number 2i.
Precision and notation
1/3 with 5 significant digits is 0.33333. 12345678 in exponential notation with 4 digits is 1.235e+7.
Common mistakes
- Using a comma as the decimal separator. The expression syntax uses a dot:
0.5. A comma separates function arguments (round(pi, 3)is3.142). - Forgetting the multiplication sign. Write
2*x; some implicit forms work, but explicit*is safer. - Mixing up
^and `.** Powers use^`. - Unbalanced parentheses. The error message shows what the parser expected.
- Expecting an error for the square root of a negative number. The result is a complex number (
2i), not an error. - Very long expressions. Anything above 5,000 characters is refused. Split the work into lines.
Frequently asked questions
What can I type in the evaluator?
Numbers, the operators + - * / ^ %, parentheses, functions such as sqrt, sin, cos, log, abs and round, constants such as pi and e, variables, units, matrices and complex numbers.
How do I convert units in a formula?
Use to: 5 cm to inch or 10 km/h to m/s. For plain length, weight or temperature conversions there is the unit converter.
Why does 0.1 + 0.2 show 0.3?
The display precision defaults to 14 significant digits, which rounds away the binary floating-point error. Raise the precision to see more digits.
Can I use variables?
Yes. Write a = 3 on one line and use a on the lines below.
Where do I do simple percentages?
In the percentage calculator or the calculator.