fm:Math


This component supports algabraic functions in the application templates.
The supported functions are: "+", "-", "*", "/", and "%".
The component allows the template developer to process 2 parameters, integers 'arg1' and 'arg2', using these algabraic operators via an operator variable called 'operator'.
The result of the component is held in a variable, which is defined in the template using 'var'. It can be called whatever you prefer it to be called, but it has to be printed in the template for the result to show.
For a complete list of the supported functions, please see the Supported Attributes table below.

Example 1: Addition

The following example will add the 2 parameters, and displays the answer: 7

<fm:Math arg1="3" arg2="4" operator="+" var="AdditionAnswer" > Answer: {$AdditionAnswer} </fm:Math>

NOTE:
The paramaters arg1, arg2 and operator are required, otherwise an error will result.
They are to be passed as arguments inside the fm:Math tags.

Supported attributes

NameRequiredDefaultDescription
%OptionalThis will calculate the remainder of argument 1 being devided by argument 2
*OptionalThis will multiply 2 arguments
+OptionalThis will add 2 arguments
-OptionalThis will subtract the 2nd argument from the 1st
/OptionalThis will divide argument 1 by argument 2
arg1RequiredN/AFirst argument of the operation
arg2RequiredN/ASecond argument of the operation
operatorRequiredAn Error will result if all 3 arguments are not providedThe mathematical operator to be used for the 2 arguments (numbers). Valid values are "+", "-", "*", "/", and "%".
randOptionalThis will display a random number between argument 1 and argument 2
varOptionalN/APopulate this var with the result of the operation, otherwise the result will be displayed

NOTE:
The paramaters arg1, arg2 and operator are required, otherwise an error will result.
They are to be passed as arguments inside the fm:Math tags.

Template variables

This component defines no template variables.

This component does not output variables, just numbers.

See also

More examples

Example 2: Multiplication:

'*' multiplies 2 integers
The following code will multiply 3 * 4 to give 12.

<fm:Math arg1="3" arg2="4" operator="*" var="MultiplicationAnswer" > Answer: {$MultiplicationAnswer} </fm:Math>

Example 3: Modulus

'%' calculates the remainder for dividing arg1 by arg2.
The following code will calculate the remainder of 5 divided by 4, which is 1.

<fm:Math arg1="5" arg2="4" operator="%" var="ModulusAnswer" > Answer: {$ModulusAnswer} </fm:Math>

Example 4: Percentage

The following example calculates the decimal and percentage for dividing arg1 by arg2.
The result wil be:
      Initial Answer: 0.428571428571
      Percentage: 42.8571428571

<fm:Math arg1="3" arg2="7" operator="/" var="PercentageAnswer1"> Initial Answer: {$PercentageAnswer1}<br> <fm:Math arg1="{$PercentageAnswer1}" arg2="100" operator="*" var="PercentageAnswer2"> Percentage: {$PercentageAnswer2}</br> </fm:Math> </fm:Math>