Math Expression Calculator

Instantly evaluate complex mathematical expressions with functions, parentheses, and exponents, all within your browser.

Trigonometric function input unit
Press Enter to save to history

Result
Calculation History Click to reload
Supported Functions ยท Constants
+ - * /Arithmetic operations
^Exponentiation ยท 2^10 = 1024
%Remainder ยท 10 % 3 = 1
( )Parentheses to specify precedence
piPi 3.14159265359
eEuler's number 2.71828182846
sqrt(x)Square root ยท cbrt(x) cube root
abs(x)Absolute value ยท sign(x) sign
sin cos tanTrigonometric functions (applies above DEG/RAD setting)
asin acos atanInverse trigonometric functions (result unit also applies setting)
log(x)Common logarithm (base 10) ยท log(x, b) for base b
ln(x)Natural logarithm ยท exp(x) is e^x
floor ceil roundFloor ยท Ceil ยท Round
min(โ€ฆ) max(โ€ฆ)Min ยท Max (multiple arguments)
pow(x, y)Exponentiation ยท same as x^y
๐Ÿ”’ This calculator parses expressions with a custom parser (Shunting-yard algorithm), not JavaScript's eval. The entered expression is calculated only within the browser and is not sent to the server, and history is also saved only in this browser.

What is the Math Expression Calculator?

Solve complex math problems in a single step. This online calculator evaluates expressions with parentheses, exponents, and standard arithmetic, plus scientific functions like `sin`, `cos`, `log`, and constants like `pi`. Simply type an expression like `sqrt(16) + 2 * (3+4)^2` and see the result appear in real timeโ€”no need to press a 'calculate' button. All calculations run entirely in your browser; your expressions are never sent to a server, ensuring your data remains private. It's free, requires no installation, and works instantly.

How to use

  1. Type or paste your equation into the "Enter expression" field.
  2. The calculation updates live, and the final answer appears in the "Result" field below.
  3. For trigonometric functions, first select your angle unit using the "DEG/RAD" toggle.
  4. Use the shortcut buttons like `pi`, `sqrt(`, and `^` to quickly add them to your expression.
  5. Press the Enter key to save the current expression and its result to the "Calculation History".
  6. Click any entry in the "Calculation History" to load it back into the calculator.

Math Expression Calculator guide

How this tool is used in real work, and what to watch out for.

Why This Calculator Uses a Custom Parser

The shortest way to compute a string like "2 * (3 + 4) ^ 2" is a single line of code: eval(expression). But this one line is a notorious security hole. That's because eval doesn't just calculate expressionsโ€”it executes any string as JavaScript code.

The moment you accept user input, your calculator becomes an "arbitrary code executor." In a browser, a user could run code to scrape cookies and login tokens and send them to an external server (XSS). If a calculator API on a server were built with eval or new Function, it would be even more catastrophicโ€”it could read files, execute commands, and completely take over the server. A simple calculator feature would create a remote code execution vulnerability.

That's why this tool uses neither eval nor new Function. It breaks the expression down into tokens (with a tokenizer), organizes the order of operations using the Shunting-yard algorithm, and then calculates the result using only allowed functions and operators. If it encounters an undefined name, it throws an error instead of executing itโ€”which is why entering alert(1) is rejected with an "Unknown name" error.

Beyond security, there are accuracy issues. `eval` follows JavaScript's rules to the letter, which can lead to implicit type conversions like "5" * "3" becoming 15. Its number parsing and operator precedence also have quirks that differ from mathematical convention. A dedicated parser interprets expressions purely as mathematics.

Try Entering 0.1 + 0.2

Enter 0.1 + 0.2 into this calculator, and you'll get 0.3. But if you do the same calculation in your browser's console, you'll see 0.30000000000000004. Is the calculator wrong? Noโ€”both computed the same value. This tool just polishes the final number before displaying it.

The cause is how computers store decimal numbers in binary. The decimal 0.1 becomes a repeating fraction in binary, so it has to be truncated at some point. This tiny error becomes apparent during addition. This isn't just a JavaScript problem; it happens in almost every language that uses floating-point numbers. This tool just hides the noise by formatting the result to 12 significant digits, but the internal calculation error is still there.

This is why you should never use this calculator (or floating-point numbers in general) for financial calculations. One or two transactions might look correct, but after accumulating thousands, the total will be off by a few cents. In accounting, that discrepancy is a disaster.

So, How Should You Calculate Money?

There is one main principle: handle money as integers, not decimals. Perform calculations using the smallest currency unit (like cents), and only apply explicit rounding or truncation rules when division is necessary.

Value-added tax (VAT) is a classic example. If you need to find the pre-tax price from a total of $290.00 with 10% tax, you get 290 / 1.1 = 263.6363... Whether to round this up or truncate it isn't a math problemโ€”it's a business and tax regulation problem. A calculator can't decide that for you; the rule must be centralized in your code.

  • In your database, use DECIMAL or NUMERIC columns instead of FLOAT or DOUBLE. Using FLOAT for money is a common but dangerous mistake.
  • When handling money in JavaScript, convert amounts to integers (e.g., cents) or use a dedicated library.
  • Don't accumulate the raw results of division. Finalize the rounding rule at each step before proceeding to the next calculation.
  • This calculator is great for sanity checks and estimations. Don't run your actual accounting logic on it.
For results over 1,000, a thousands separator is shown above the result field. This makes it easier to estimate large amounts without having to count zeros.

Five Common Syntax Gotchas

The error message will tell you the approximate character position of the problem, but the issues below can be tricky to diagnose if you don't know what to look for.

InputResultReason
2(3+4)ErrorThe multiplication operator cannot be omitted. Use 2*(3+4).
30 % 50% is the remainder (modulo) operator, not percentage. For a 30% discount, use 30/100.
2^3^2512Exponentiation is right-associative. This is evaluated as 2^(3^2) = 2^9.
-2^2-4Exponentiation has higher precedence than the unary minus, so this is interpreted as -(2^2).
log(100)2log is the common logarithm (base 10). For the natural logarithm, use ln(x).
The log function is especially confusing. Scientific calculators and Excel treat log as base 10, but most programming languages use log for the natural logarithm. This tool follows the calculator convention, using log for base 10 and providing ln for the natural logarithm. To specify a base, use a second argument, like log(8, 2).
Trigonometric functions obey the DEG/RAD setting at the top. In DEG mode, sin(30) is 0.5, but in RAD mode it's a completely different value. If your result looks wrong, check this setting first. The unit of the result for inverse trigonometric functions also follows this setting.

Large Number Limits and History

If a result exceeds 9,007,199,254,740,991 (2^53 - 1), a warning appears: 'Value exceeds 2^53, so the last digit is an approximation'. This is because JavaScript's standard number format cannot accurately represent integers larger than this. Calculations like 2^100 will produce a value, but it won't be an exact integer. For arbitrary-precision arithmetic, use a language like Python or an environment that supports BigInt.

Pressing Enter after entering an expression saves it to the Calculation History. It stores up to 10 entries. Clicking an item in the history reloads that expression into the input box, which is handy for repeating similar calculations with different values.

  • History and your last entry are saved only in this browser. They are not sent to the server and will not be visible on other devices.
  • If you've calculated sensitive numbers on a public computer, be sure to click "Clear History" when you're done.
  • Undefined calculations like division by zero, the square root of a negative number, or tan(90ยฐ) are caught as errors instead of producing strange values like Infinity or NaN.
  • The chip buttons (pi, sqrt(, round(, etc.) insert text directly at your cursor's position. You don't need to memorize the function names.

Frequently asked questions

What functions and operators are supported?

It handles arithmetic (+, -, *, /), exponents (^), and parentheses. It also supports functions like `sqrt`, `log`, `ln`, `sin`, `cos`, `tan`, `abs`, `round`, and constants like `pi` and `e`. See the "Supported Functions ยท Constants" table for a complete list.

Are my calculations and data secure?

Yes. This tool is designed for privacy. All calculations are processed directly in your web browser. Nothing you enter is sent to a server, and the "Calculation History" is stored only on your local device.

How do I calculate with degrees instead of radians?

Use the "DEG/RAD" toggle above the input field. Select "DEG" to work with degrees, where `sin(90)` will correctly yield `1`. When "RAD" is selected, all trigonometric function inputs are treated as radians.

Why is my result shown in scientific (e) notation?

Results are shown in scientific notation (e.g., `1.23e+15`) when they are very large or small, for accuracy and readability. Note that due to standard floating-point limits, integers above ~9 quadrillion (2^53) may be approximations.