How to Make Your Own Online Calculator

I have designed a calculator for my personal work and realized how difficult it was. For mu online calculator I used following specifications-:

PHP, HTML, CSS and JavaScript

One input field, where you will input your values

Result history of last five queries

It allows all the trigonometric functions

It also involves Pi, Square root and logarithm functions

You can have a view at calcolatrice.io that is an online calculator and solves all the mathematical operations easily.

The most difficult thing is the "one input field"-thing. If you allow your user to write numbers and operators in the same input field then you require a separate input field to perform the calculations. For example, determine the different meanings of the substring "-7" in "sqrt(6-7+5)" and "sqrt(-7+5)"? The answer is regular expressions.

When you design your own calculator you have to use regex to separate numbers, operators and functions. Take this string for example: "3+4.2-1". You have to break it into 3 parts and you then you should be aware that which are pars that are operators and which parts that are numbers. When this is done, your half work is completed.  Then you have to evaluate the expressions in the correct order, put the results and evaluate the parts again.  Pi, square root etc is solved with built in PHP functions.

You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *