Toolvito

Works on this device

Calculator Builder

Make a calculator of your own without writing a program. Name each input, give it a value, and write a formula for each result, such as price * qty. The page works the calculator out at once, can test it over a range of values, and gives you the calculator as one HTML file to open or put on your site.

Enter your values

Name your inputs, write a formula for each result, and the calculator works. Change a value and choose Work it out again.

Your values

Inputs

Results

This is off unless you turn it on. Saved entries stay in this browser only. Untick the box to delete them.

Your values are worked out in this browser. They are not sent to a server.

Your result will show here

Fill in the values, then choose Work it out.

How to build a calculator

  1. Give the calculator a title.
  2. Under Inputs, add a row for each value the user types: a Name in formulas (letters only, such as price), a Label that people read, a Value to start with and, if you want, a Unit.
  3. Under Results, add a row for each answer: a Label, a Formula made of the input names, and the number of Decimals to show. Give a result a Name for later formulas if a result below it uses it, such as subtotal.
  4. Choose Work it out. The results are shown at once. Change a value and choose it again.
  5. Choose Test the calculator over a range of one input to see a table of results while one input changes, for example to check the formulas.
  6. Download the Calculator file (HTML) to use the calculator on its own, or the Calculator definition (JSON) to open it here again later with Open a saved calculator file. Tick Save my entries on this device to keep your work in this browser.

How formulas are read

  • A formula can use the names of the inputs and of the results above it, numbers with a decimal point, + - * /, ^ for powers (2^3 = 8), brackets, and the functions sqrt, abs, ln, log (base 10), log2, logb(base, x), exp, sin, cos, tan, asin, acos, atan (angles in radians), the factorial n!, and the constants pi and e.
  • A number or a bracket straight before a name means multiplication: 2x is 2 × x, and 2(a + b) is 2 × (a + b). Every word in a formula must be exactly the name of an input, of a result above, of a function or of a constant, so write * between two names: a * b, not ab.
  • Capital and small letters are the same in names. A name cannot be the name of a function or a constant (such as log or e), and each name can be used only once.
  • The page reads each formula into a tree of numbers, names and signs and works it out from the tree. It never runs typed text as code. A result that has no value (a division by zero, the square root of a negative number) is named with its row.
  • The results are worked out from the first row down. Decimals change only how a result is shown; a later formula uses the full value.
  • There are no if, min, max or rounding functions yet. A result cannot be a date or a text.

The calculator file

  • The HTML file has your inputs (as number boxes with your starting values) and your results, and it works them out again whenever a value changes.
  • It holds each formula as a tree, and a short function that works the tree out with the same steps as this page. It does not use eval and does not load anything from the internet.
  • Results in the file are shown with the browser's number format and the decimals you chose, such as 1,234.50.
  • To put it on a web site, upload the file, or copy its parts into your page. Some site builders do not allow scripts in a page; then link to the file instead.

Worked example

The starting calculator has the inputs price = 19.99 (USD), qty = 3 and tax = 8 (%). The results are: Subtotal = price * qty = 59.97 USD; Tax = subtotal * tax / 100 = 4.7976, shown as 4.80 USD; Total = subtotal + taxamount = 64.7676, shown as 64.77 USD.

Testing it with qty from 1 to 10 in 10 rows gives totals from 21.59 (1 item) to 215.89 (10 items) USD.

Limits you should know

  • Up to 30 inputs and 20 results. Numbers are worked out in floating point, the way spreadsheets and calculators do, so a result can differ from the exact value in the last digits.
  • This page builds calculators for formulas you know. It does not know prices, tax rates or costs; type the values yourself.
  • This page is not a form builder: it does not take payments, send results or save them on a server.
  • For ready-made calculators of prices in the cloud, building costs or a PC build, see the related tools of this site.

Related tools