-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
76 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,92 @@ | ||
ExpressionEngine Math Plugin 1.4.0 | ||
==== | ||
## Math 1.4.0 | ||
|
||
Use Math to execute PHP supported math formulas in ExpressionEngine. | ||
Math allows you to execute many PHP math functions in your ExpressionEngine templates without needing to enable PHP parsing. | ||
|
||
Parameters: | ||
## Parameters | ||
|
||
formula = '(5 * 2) / [1]' // math formula (required) supports the following operators as well as bitwise + - * / % ++ -- < > <= => != <> == | ||
### formula="(5 * 2) / [1]" | ||
|
||
params = '{var}|{var2}' // pipe delimited list of numeric parameters to be replaced into formula, recommended due to use of PHP eval (default: null) | ||
This is a required parameter and supports the following standard PHP operators as well as bitwise operators: | ||
|
||
decimals = '2' // sets the number of decimal points (default: "0") | ||
+ - * / % ++ -- < > <= => != <> == | ||
|
||
decimal_point = '.' // sets the separator for the decimal point (default: ".") | ||
Example: | ||
|
||
thousands_seperator = ',' // sets the thousands separator; (default: ",") | ||
{exp:math formula="10 - 2"} | ||
|
||
absolute = 'yes' // return the absolute number of the result (defaults: "no") | ||
Output: 8 | ||
|
||
round = 'up|down|ceil' // whether to round the result up or down (defaults: no rounding) | ||
### params="{var}|{var2}" | ||
|
||
numeric_error = 'Error' // message returned when non-numeric parameters are provided (default: "Invalid input") | ||
This is a pipe delimited list of numeric parameters to be replaced into formula, recommended when using dynamic parameters (default: null). | ||
|
||
trailing_zeros = 'yes' // include trailing 0 decimal places (defaults: "no") | ||
Set your params and call them by bracketed number in order of listing. So for instance [1] would call the first set param, [2] would call the second set param and so forth. | ||
|
||
Usage: | ||
Example: | ||
|
||
{exp:math formula="10 - 12" absolute="yes"} outputs 2 | ||
{exp:math formula="[1] - [2]" params="{var1}|{var2}"} | ||
|
||
{exp:math formula="((4 * 5) / 2)" decimals="2"} outputs 10.00 | ||
### decimals="2" | ||
|
||
{exp:math formula="([1] + 1) / [2]" params="{total_results}|2" round="down"} outputs 5 where {total_results} is 10 | ||
Sets the number of decimal points (default: "0") | ||
|
||
{exp:math formula="2/3" decimals="2" round="up"} outputs 0.67 | ||
Example: | ||
|
||
{exp:math formula="((4 * 3) / 5)" decimals="1"} | ||
|
||
Output: 2.4 | ||
|
||
### decimal_point="." | ||
|
||
Sets the separator for the decimal point (default: ".") | ||
|
||
### thousands_seperator="," | ||
|
||
Sets the thousands separator (default: ",") | ||
|
||
### absolute="yes" | ||
|
||
Return the absolute value of the result (defaults: "no") | ||
|
||
Example: | ||
|
||
{exp:math formula="10 - 12" absolute="yes"} | ||
|
||
Output: 2 | ||
|
||
### round="up|down|ceil" | ||
|
||
Whether to round the result up or down (defaults: no rounding) | ||
|
||
Example: | ||
|
||
{exp:math formula="([1] + 1) / [2]" params="{total_results}|2" round="down"} | ||
|
||
Output: 5 (where {total_results} is 10) | ||
|
||
{exp:math formula="2/3" decimals="2" round="up"} | ||
Output: 0.67 | ||
|
||
### numeric_error="Error" | ||
|
||
Message returned when non-numeric parameters are provided (default: "Invalid input") | ||
|
||
### trailing_zeros="yes" | ||
|
||
Include trailing 0 decimal places (defaults: "no") | ||
|
||
## License | ||
|
||
Copyright 2014 Caddis Interactive, LLC | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |