How to create an online calculator

How to create an online calculator

 


InformationVideo Demo

See an online demo of creating a calculation field here: Creating an order form with calculations using Simfatic Forms


 

The calculation field feature in Simfatic Forms can be used to do complex calculations live.

 

This article shows you an example that breaks a complex formula and logic for a tax calculation.

Note that the rules used are fictitious. You can assume any currency or any country.

 

Having said that, here are the rules of the land:

 

  • You have got the total yearly income
  • Contribution to retirement plan can be deducted (upper limit 10,000)
  • The first 100,000 of the total income is not taxable; 30% tax for the rest
          • Example: if the income is 100,000 then there is no Tax.
          • If the income is 110,000 then tax should be paid for 10,000. That is, tax = 30% of 10,000)
  • For senior citizens and women, there is no tax for the first 150,000
  • There is a 10% tax rebate for House Rent ( upper limit 100,000 )
  • There is a 20% tax rebate for Medical Expenses ( upper limit 15,000 )

Here, we have the form:

Calculation form

 

It is always better to break a big formula into smaller ones.

 

Part I : Taxable Income

To calculate the taxable income, we have to deduct the 'contribution to retirement plan' from the total income.

 

taxable_income = total_income - retirement_plan_contribution

 

But, there is an upper limit to the retirement_plan_contribution. Simfatic Forms provides several functions. The min() function returns the minimum of the inputs. So, can make it this way:

 

taxable_income = total_income - min(retirement_plan_contribution,10000)

 

 

Now, there is a discriminating minimum income limit. We take the input from the 'Gender' radio button. Here is the updated formula:

 

 

taxable_income = total_income -  min(retirement_plan_contribution,10000) - Gender

 

 

When we add a radio button or dropdown list to the formula, we get a new tab in the 'Value maps' tab of the formula editor. This is to map the selection to its numeric value.

 

For example, if the 'Gender' is Male, we need to use 100000 and for Female, 150000.

Value map

 


InformationValue Maps

When you are using a selection (radio group, dropdownlist) in a formula, you may have to map the selected value to a corresponding numeric value. Simfatic Forms' value map makes this easy. If your formula contains a selection, the value maps tab will have mapping for each of such inputs. Just provide the numeric value to be used in the calculation.


 

There is, an additional rule that Senior citizens also get the 150000 limit. So, we update the formula such that if not SeniorCitizen, take the Gender based limit. It SeniorCitizen, then always deduct 150000. Here is the updated formula:

 

 

taxable_income = total_income -  min(retirement_plan_contribution,10000 )

                - !SeniorCitizen * Gender - SeniorCitizen * 150000

 

Notice that the check box 'SeniorCitizen' returns 1 if checked and 0 if not checked.

 

Part II : Calculate Tax

We now has the final taxable income. Tax is 30% of the taxable income. Simfatic Forms has a function perc_of() to calculate percentage.

 

tax_before_deductions = perc_of(taxable_income,30)

 

To reach the tax payable, we need to deduct the tax rebates.

 

tax_payable = tax_before_deductions

              -  perc_of( min( HouseRent ,100000),10)

              -  perc_of( min( medical ,15000),20)

 

 

We have got the final tax amount. But there is a problem; the tax can become negative if the income is low !

I know no government that pays tax to the citizen : )

 

We can fix this by having the formula below

 

tax_displayed = min(tax_payable,0)

 

You can use hidden calculation fields to keep the intermediate results. In this calculation, taxable_income and tax_payable can be hidden; displaying only tax_displayed to the user.

 


idea

 

During the design phase, keep the intermediate results visible so that you can see how the calculation goes. Once the calculations are working, you can make them hidden.

 

 


 

See Also:

Calculation Field

 

Calculation field : function reference

 

Formula editor