Coder Social home page Coder Social logo

math's Introduction

Math 1.5.1

Math allows you to execute many PHP math functions in your ExpressionEngine templates without needing to enable PHP parsing.

Quick Tag Reference (full documentation below)

formula="(5 * 2) / [1]" — math formula (required) supports the following operators as well as bitwise + - * / % ++ -- < > <= => != <> ==
params="{var}|{var2}" — pipe delimited list of numeric parameters to be replaced into formula, recommended due to use of PHP eval (default: null)
decimals="2" — sets the number of decimal points (default: "0")
dec_point="." — sets the separator for the decimal point (default: ".")
thousands_separator="," — sets the thousands separator; (default: ",")
absolute="yes" — return the absolute number of the result (defaults: "no")
round="up|down|ceil" — whether to round the result up or down (defaults: no rounding)
numeric_error="Error" — message returned when non-numeric parameters are provided (default: "Invalid input")
trailing_zeros="yes" — include trailing 0 decimal places (defaults: "no")

Parameters

More detailed reference.

formula="(5 * 2) / [1]"

This is a required parameter and supports the following standard PHP operators as well as bitwise operators:

+ - * / % ++ -- < > <= => != <> ==

Example:

{exp:math formula="10 - 2"}

Output: 8

params="{var}|{var2}"

This is a pipe-delimited list of numeric parameters to be replaced into the formula, recommendeded when using dynamic parameters (default: null).

Set your parameters and call them by bracketed number reference. For instance [1] would call the first value, [2] would call the second value, and so forth.

Example:

{exp:math formula="[1] - [2]" params="{var1}|{var2}"}

decimals="2"

Sets the number of decimal points (default: "0")

Example:

{exp:math formula="((4 * 3) / 5)" decimals="1"}

Output: 2.4

dec_point="."

Sets the separator for the decimal point (default: ".")

thousands_separator=","

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")

Installation

EE 2

DevDemon Updater is fully supported, or for manual installs copy "system/expressionengine/third_party/math" to your third_party system directory.

EE 3

  1. Copy "system/expressionengine/third_party/math" to "system/user/addons"
  2. Go to your control panel and navigate to the Add-On Manager
  3. Locate Math in the Third Party Add-Ons section and click install

License

Copyright 2016 Caddis Interactive, LLC. Licensed under the Apache License, Version 2.0.

math's People

Contributors

leigeber avatar adrienne avatar taylordaughtry avatar nathanhood avatar

Watchers

James Cloos avatar  avatar

Forkers

cantilever

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.