Lesson Summary
This lesson introduced some of the most common numeric functions in the Expression Engine. Some of these functions complement one another, in the sense that they either produce an opposing effect, or they reverse the effect of the other:
- The Sqr function raises its single argument to the power of 2, which is useful in a number of mathematical functions including Pythagorean theorem and quadratic equations.
- The Sqrt function finds the square root of its single argument, reversing the effect of the Sqr function, and vice versa.
- The Max function takes two numeric arguments and returns the greater value.
- The Min function takes two numeric arguments and returns the lesser value.
- The Abs function takes a numeric value and returns only the number part, excluding the sign.
- The Sign function takes a numeric value and returns a value depending on whether it is negative (-1), positive (1) or zero (0).
- The Ceil function takes a numeric value and, if it has any decimal places, rounds the value up to the next integer.
- The Floor function takes a numeric value and, if it has any decimal places, rounds the value down to the next integer.
- The Rnd function requires no arguments, and evaluates to a random fraction between 0.0 and 1.0, inclusive.
These functions can be nested inside other functions and combined with arithmetic, logical and conditional operators to produce rich mathematical expressions for calculating complex information. You should now be confident how each of them works and why you might need to use them.
<< Previous: Random (Rnd) | Next: Test Your Knowledge! >>