Using the Formula (formerly Total) element, you can build any formula for your Calculator. For that, you should add available Fields and Operators via clicking on them.
The Formula element contains the following attributes:
Name - Give the description of the total calculation
Calculator Formula area - Create your own formula for the calculator
Available Operators - This field contains mathematical operators and functions that can be used in the formula
Available Fields - This field contains all elements of the created calculator form with their ordered IDs.
Show Alternative Symbol - Enables field to enter an alternative symbol
Hidden by Default - The element will be hidden until a corresponding condition is met
Additional Classes - Add extra classes to the HTML elements to further style changes
In the available operators' section, you can see mathematic operations like addition (+), subtraction (-), division (/), multiplication (*), percentage (%), and mathematical methods which will be listed below:
round(x) - returns the value of x rounded to its nearest integer: round(4.7)=5
pow(x,y) - returns the value of x to the power of y: pow(8, 2)=64
sqrt(x) - returns the square root of x: sqrt(25)=5
abs(x) - returns the absolute (positive) value of x: abs(-3.7)=3.7
ceil(x) - returns the value of x rounded up to its nearest integer: ceil(4.4)=5
floor(x) - returns the value of x rounded down to its nearest integer: floor(8.7)=7
You can review the mathematical methods here to get more information. Note: All these methods are written with a Math prefix since they are objects inherited from the Math library.
Please create a correct formula in Total element paying attention to element field IDs, opening and closing paratheses in nested formulas in order not to face some wrong results in the calculation summary.
Let's see the example of the Formula element:
You can watch a tutorial about the custom conditions and how to use if/else statements.
It is possible to create an if/else statement in the Calculator formula field of the Total Element. Using if/else statements, you can handle some situations and set conditions.
Now, let's see the Loan Calculator which is built with a quantity, two range buttons, and total elements as a sample example. Here is the standard formula for calculating the loan amount:
And now we will create an if/else statement so that the total sum of a loan calculator should be higher than or equal to 500 like below:
So, according to the formula above, the loan amount will be always higher than or equal to 500. Please check the following pictures:
The result of if statement:
The result of else statement:
If you want to apply a separate if/else statement for each field and set a separate Total element for each statement. We recommend you to use the Summary Total formula to get the sum of all Total elements and to avoid a complex calculation process.
In the following example, different if/else statements were used for each Total element. And the Summary Total formula is calculating the overall sum of these two Total elements:
The Alternative Symbol option is available in order to display multiple Total fields with different calculations and symbols.
The inserted symbol in the Alternate Symbol field takes precedence over the currency symbol in the Settings menu.
The Alternative Symbol is displayed after pasting the symbol to the appropriate field.
If you are using the currency symbol in the Alternative Symbol field and want to integrate the Calculator with WooCommerce, then you have to consider whether WooCommerce supports that currency.