[Math ResultType]Equation[/Math]

Calculates the enclosed numerical, date, or time equation and displays the results.

To calculate a mathematical equation, put it inside a Math context. You may put any [xxx] variables inside the context. Dates and times can also be calculated -- to distinguish dates from plain numbers, put them inside curly-braces like so: {12/01/1997}.

Example (normally you would put the following text into a .tpl file on your server and use a web browser to link to it):

[Math](4.5+6.2)/17*95-12[/Math]
[Math]{4/7/1997}+10[/Math]
[Math]{4/7/1997}+{02/00/0000}[/Math]
[Math date]{4/7/1997}+10[/Math]
[Math date]{4/7/1997}+{02/00/0000}[/Math]
[Math date]{[date]}-{00/07/0000}[/Math]
[Math]{12:51:02}[/Math]
[Math time]{12:51:02}+{01:00:05}[/Math]
[Math]x=5/3[/Math]
[Math show=F]x=5/3[/Math] (2.0.1)

Try It!

In the example above, the displayed text will be

```47.794117647
195402 (4/7/1997 + 10 days expressed as number of days since 00/00/0000 (AD))
195462 (4/7/1997 + 2 months expressed as days since 00/00/0000)
04/17/1997 (4/07/1997 + 10 days expressed as date)
06/07/1997 (4/17/1997 + 2 months expressed as date)
03/30/1997 (One week ago today)
46262 (number of seconds between midnight and 12:51:02 expressed as seconds)
13:51:05 (12:51:02 pm plus 1 hour and 5 seconds expressed as time)
1.66666667
(no output) show=F means not to display the results of the equation```

Any [xxx] variables are first evaluated and replaced with their real values, and then the resulting equation is calculated. The final numerical result is displayed. Standard algebraic order of operations are followed when evaluating expressions. Use parentheses to clarify or force a specific order of operations.

Example: An invoice template might show the line-item cost of each item like so:

[LineItems]
[sku], [title], [description], [price], [math]([price]+[unitShipCost])*[quantity][/math]
[/LineItems]

Date Math:

Dates may be included in mathematical expressions by enclosing the date in braces ( '{' and '}' ). You may easily add or subtract days, months, or years from dates by expressing them as a complete date. Use 0 for values that you want ignored. That is, in order to add 2 months to today's date you would write an expression like the following [math date]{[date]}+{2/0/0000}[/math]. It is a good idea to group math expressions involving dates together using parentheses.

Note that the year must be expressed as 4 digits so that 2-digit years can be converted to their proper value (i.e. 96 is really 1996, and 00 is 2000).

When using dates mixed with integers, the final result is a value respresenting a number of days (e.g. {12/8/97}+10 adds 10 days to the date). In fact, the result of a math expression with dates is always the number of days. To display the output of the math expression as a date, add the Date modifier to the [math] context: [math date]...[/math].

Time Math:

Times may be included in mathematical expressions by enclosing the time in braces ( '{' and '}' ). You may easily add or subtract hours, minutes, or seconds from times by expressing them as a complete time. Use 0 for values that you want ignored. That is, in order to add 2 mintes to the current time you would write an expression like the following [math time]{[time]}+{00:02:00}[/math]. It is a good idea to group math expressions involving times together using parentheses.

When using times mixed with integers, the final result is a value respresenting a number of seconds (e.g. {10:15:31}+10 adds 10 seconds to the time). In fact, the result of a math expression with times is always the number of seconds. To display the output of the math expression as a time, add the Time modifier to the [math] context: [math time]...[/math].

Note: you may want to convert an integer number to a date. Use [Format Days_To_Date] and [Format Seconds_To_Date] to convert integer numbers to their equivalent dates. The integer number represents the number of days since mindight, January 1, 1900 and for times it represents the number of seconds since midnight.
```[Format Days_To_Date]195402[/Format] yields 4/17/1997
[Format Seconds_To_Date]46262[/Format] yields 12:51:02```
Tip: sometimes you want to calculate something without displaying the results, perhaps while calculating a running total. To do this, add "show=F" to the math parameters, as in [Math show=F]total=total+[subTotal][/Math]. This allows you to perform calculations in the middle of a web page without the intermediate numbers appearing to the visitor. Later, you can show the value of the math variable with [Math]total[/Math].

Scientific Functions:

You may include scientific functions inside a Math context, like so: [math]ceil(1.5)[/math], or [math]sin([formvalue])*cos(3.1415)[/math]

Function

Description

sin(x)

returns sine of x

cos(x)

returns cosine of x

tan(x)

returns tangent of x

asin(x)

returns arcsine of x

acos(x)

returns arccosine of x

atan(x)

returns arctangent of x

sinh(x)

returns hyperbolic sine of x

cosh(x)

returns hyperbolic cosine of x

tanh(x)

returns hyperbolic tangent of x

log(x)

return natural log of x

log10(x)

returns log base 10 of x

sqrt(x)

returns square root of x sqrt(16) = 4

floor(x)

rounds down to next-lower integer. floor(2.9) = 2

ceil(x)

rounds up to next-higher integer. ceil(3.1) = 4

abs(x)

returns absolute value of x. abs(-3.4) = 3.4

deg(x)