The mgiMath Tag

Tag Behavior

The mgiMath tag performs calculations and displays the result in a specified format.


Tag Syntax

The mgiMath tag has one required parameter and one optional parameter for all functions. In addition, the mgiMath tag has required and optional parameters for specific functions. The tag form is:

<mgiMath function="Function" functionParameter="Value" 
format="Display">

Required Parameters for all Targets:

  • function="Function" where "function" is the operation to perform. See the specific required and optional parameters for each function below.
    • "absoluteValue" - calculates the absolute value (1 required, 1 optional parameter).
    • "negate" - calculates the negative value (1 required, 1 optional parameter).
    • "add" - calculates the sum of two values (2 required, 1 optional parameters).
    • "subtract" - calculates the difference between two values (2 required, 1 optional parameters).
    • "multiply" - calculates the product of two values (2 required, 1 optional parameters).
    • "divide" - calculates the quotient of two values (2 required, 1 optional parameters).
    • "loanPayment" - calculates the periodic loan payment based on constant payments and a fixed interest rate (3 required, 2 optional parameters).
    • "loanFutureValue" - calculates the future value of an investment based on periodic, constant payments and a fixed interest rate (3 required, 2 optional parameters).

Optional Parameter for all Functions:

  • format="Display" where "Display" is the syntax for displaying the result of a calculation. Each function has a default result format (see below). Custom result formats can be created with the following components:
    • (#) - displays a numeric digit of the result.
    • (.) - displays a decimal point.
    • (+) - displays result rounded to positive infinity (rounded up).
    • (-) - displays result rounded to negative infinity (rounded down).

Format examples

    • "###.##" - displays at least 3 digits prior to the decimal point and only 2 digits following the decimal point.
    • "#.####+" - displays at least 1 digit prior to the decimal point and only 4 digits following the decimal point rounded toward positive infinity.
    • "###-" - displays at least 3 digits without a decimal and rounded toward negative infinity.
    • " " - displays all digits

AbsoluteValue Function Parameters:

Required

  • value="Operand" where "Operand" is the number whose absolute value is calculated and displayed.

Optional

  • format=" " The default format of the absolute value function.

Negate Function Parameters:

Required

  • value="Operand" where "Operand" is the number that is negated.

Optional

  • format=" " The default format of the negate function.

Add Function Parameters:

Required

  • lhs="LeftOperand" where "LeftOperand" is the number on the left-hand side of the addition operator (+).
  • rhs="RightOperand" where "RightOperand" is the number on the right-hand side of the addition operator (+).

Optional

  • format=" " The default format of the add function.

Subtract Function Parameters:

Required

  • lhs="LeftOperand" where "LeftOperand" is the number on the left-hand side of the subtraction operator (-).
  • rhs="RightOperand" where "RightOperand" is the number on the right-hand side of the subtraction operator (-).

Optional

  • format=" " The default format of the subtract function.

Multiply Function Parameters:

Required

  • lhs="LeftOperand" where "LeftOperand" is the number on the left-hand side of the multiplication operator (*).
  • rhs="RightOperand" where "RightOperand" is the number on the right-hand side of the multiplication operator (*).

Optional

  • format=" " The default format of the multiply function.

Division Function Parameters:

Required

  • lhs="LeftOperand" where "LeftOperand" is the number on the left-hand side of the division operator (/).
  • rhs="RightOperand" where "RightOperand" is the number on the right-hand side of the division operator (/).

Optional

  • format=" " The default format of the division function.

LoanPayment Function Parameters:

Required

  • rate="Decimal Number" where "Decimal Number" is the interest rate for each period of the loan (e.g. for a loan with monthly payments, the monthly interest rate).
  • periods="Units" where "Units" is the number of periods in the loan (e.g. a 4 year loan with monthly payments has 48 payment periods).
  • presentValue="Decimal Number" where "Decimal Number" is the present value of the loan (e.g. the original loan amount).

Optional

  • futureValue="Decimal Number" where "Decimal Number" is the future value of the loan. The default is "0.00".
  • format="#.##+" The default format of the loanPayment function.

LoanFutureValue Function Parameters:

Required

  • rate="Decimal Number" where "Decimal Number" is the interest rate for each period of the investment (e.g. for a monthly investment, the monthly interest rate).
  • periods="Units" where "Units" is the number of periods in the investment (e.g. a monthly investment over 10 years has 120 units).
  • payment="Decimal Number" where "Decimal Number" is amount invested during each period.

Optional

  • presentValue="Decimal Number" where "Decimal Number" is the present value of the loan. The default is "0".
  • format="#.##+" The default format of the LoanFutureValue function.


Example Usage and Output

<mgiMath function="add" lhs="2" rhs="2">

This mgiMath example is simply adding 2 plus 2. The result of this calculation will display as:

4
<mgiMath function="multiply" lhs="3.58" rhs="7.29" format="##.#+">

The full result of this multiplication calculation is 26.0982, but the custom format will display the result as:

26.1
$<mgiMath function="divide" lhs="10.999" rhs="2" format="##.##+">

This result is intended to be displayed as a currency value, but the dollar sign ($) should be coded outside of the mgiMath tag. The result of this calculation will display as:

$05.50


Suggested Usage

  • Conditional Comparisons
  • Variables


[Return to the Referencing MGI Menu]


[User Guide Main Menu] [Understanding MGI Menu] [Using MGI Menu] [Referencing MGI Menu]