Skip to content
Daniel Poulin edited this page Jul 2, 2012 · 1 revision

Mathematical Helpers

Modulo

This applies the modulo operator to a numerator and denominator. Useful for outputting stuff every third, fourth, etc entry in a loop.

Parameters

  • numerator: The number on top of the fraction.
  • denominator: The number on bottom of the fraction.

Usage Example

If we are attempting to output something every third iteration of a channel entries, we could do the following:

{exp:channel:entries channel="blog"}
	{if '{exp:surgeree:modulo numerator="{count}" denominator="3"}' == 0}
		{count}
	{/if}
{/exp:channel:entries}

That will output the following, for a channel consisting of 16 entries:

3
6
9
12
15

Round Divide

Applies division to passed parameters, then rounds up or down. Defaults to up.

Parameters

  • numerator: The number on top of the fraction.
  • denominator: The number on bottom of the fraction.
  • round: Whether to round the value up or down.
    • Default: up

Usage Example

{exp:surgeree:round_divide numerator="4" denominator="3"}

Will output:

2

Format Number

Formats numbers according to passed parameters. Useful for localization.

Parameters

  • number: The number to format.
  • precision: How many digits past the decimal separator to output.
    • Note: Setting this value much higher than the precision of the number value is likely to give you values that are slightly off (e.g. 3.01 -> 3.010000000057). This is due to issues with php's conversion of strings to numbers.
    • Default: 2
  • decimal: What character to use for the decimal separator.
    • Default: .
  • separator: What character to use for the "thousands separator".
    • Default: ,
  • groupsize: How many decimal places to group a number by with the "thousands separator".
    • Default: 3

Usage Example

{exp:surgeree:format_number number="12343.90" precision="1" decimal="," separator="'" groupsize="4"}

Will output:

1'2343,9
Clone this wiki locally