Formula Calculator
Multi-line formula calculator with variables, SI prefixes, and implicit multiplication
What is the Formula Calculator?
The Formula Calculator is an online calculation tool that supports multi-line variable definitions, real-time evaluation, and automatic dependency propagation. You write calculation logic line by line like code — each line defines a variable or evaluates an expression, with results displayed immediately in the right panel. It runs entirely in the browser with no server required, making it ideal for engineers, students, and developers who need quick engineering computations.
How to Use the Formula Calculator
Type formulas line by line in the editor. Use name = expression syntax to define variables that subsequent lines can reference. Pure expressions (without =) are evaluated directly and their results shown. Lines starting with // are comments and are ignored. All formulas are automatically saved to the browser's IndexedDB, so they persist across page refreshes.
Example: a = 10 b = a * 3 sqrt(b) Result: a = 10, b = 30, and the last line shows 5.477...
SI Prefixes and Implicit Multiplication
Common SI prefixes are supported: T (10^12), G (10^9), M (10^6), k (10^3), m (10^-3), u (10^-6), n (10^-9), p (10^-12). For example, 10k equals 10000 and 4.7u equals 0.0000047. A number directly followed by a variable name automatically inserts multiplication: 2PI is equivalent to 2*PI, and 3R1 is equivalent to 3*R1. SI prefixes can also combine with variables — in 10kOhm, if Ohm is a known variable, it resolves to 10000*Ohm.
Built-in Functions and Constants
Built-in math functions: sin, cos, tan, asin, acos, atan, atan2, sinh, cosh, tanh, sqrt, cbrt, exp, log (natural logarithm), log2, log10, abs, ceil, floor, round, pow, max, min, sign, trunc.
Additional functions: gcd (greatest common divisor), lcm (least common multiple), isPrime, clamp, deg2rad, rad2deg.
Display format functions: bin(x), hex(x), oct(x) — show numbers in binary, hexadecimal, or octal.
Built-in constants: PI, E, LN2, LN10, LOG2E, LOG10E, SQRT2, SQRT1_2, Infinity, INT_MAX, INT_MIN, UINT_MAX, LONG_MAX, LONG_MIN, ULONG_MAX.
Number Formats and Operators
Multiple number formats are supported in expressions: - Hexadecimal: 0xFF (equals 255) - Binary: 0b1010 (equals 10) - Octal: 0o77 (equals 63) - Percentage: 50% (equals 0.5)
Special operators: - Power: a ^ b computes a raised to the power of b - Conditional: condition ? valueIfTrue : valueIfFalse - Comparison and logical operators: >, <, >=, <=, ==, !=, &&, ||, !
User-Defined Functions and Angle Mode
Define custom functions using arrow syntax: f = x => x^2 f(3) // → 9
g = (a, b) => sqrt(a^2 + b^2) g(3, 4) // → 5
User functions can reference previously defined variables and are called like built-in functions.
Angle Mode: Click the DEG/RAD button to switch between degree and radian mode for trigonometric functions. In DEG mode, sin(90) = 1; in RAD mode, sin(PI/2) = 1.