{avg:val1:val2:...}

Description

Returns the arithmetic mean (average) of the values you give it. Values are passed colon-separated, as in avg:12:45:8, or as a single JSON array, as in avg:[12,45,8] - both average the same three numbers. With one value it returns that value; with no values it returns an empty string. The result is a true division and is never rounded - a repeating decimal prints with PHP default precision (for example avg:12:45:8 gives 21.666666666667); wrap it in round or number_format for fixed decimals. Each value is read as a number: comma decimal separators are normalized to dots, and non-numeric text is read as 0 but still counts toward the divisor. In the JSON-array form only, empty-string entries are dropped before averaging (zero is kept). Companion commands: max and min.

Parameters

value1:value2:... required default (none - at least one value)

The numbers to average, each as a separate colon-separated argument: {avg:12:45:8}. Give two or more for a real mean; a single value returns itself and no values returns an empty string. As an alternative, pass one JSON array instead: {avg:[12,45,8]}. Decimal commas are normalized to dots; non-numeric text is read as 0 (but still counts in the divisor); in the JSON form empty-string entries are dropped before averaging.

Examples

test{avg:10:20:30}
Expected20
Actual20
The everyday case: pass two or more numbers separated by colons and {avg:} returns their arithmetic mean. With (10+20+30)/3 the result is 20.
test{avg:3:4}
Expected3.5
Actual3.5
The mean is a true division, not rounded: (3+4)/2 is 3.5. avg never rounds - it prints the exact PHP float.
test{avg:5}
Expected5
Actual5
One value averages to itself. avg with a single argument returns that value unchanged.
test{avg:[10,20,30]}
Expected20
Actual20
The second accepted form is a JSON array in square brackets. {avg:[10,20,30]} is the same as {avg:10:20:30}. Useful when the list comes from a JSON-producing command.
test{avg:12:45:8}
Expected21.666666666667
Actual21.666666666667
A repeating decimal is printed with PHP default precision (14 significant digits), not rounded to a tidy number. (12+45+8)/3 is 21.666666666667. Wrap avg in {round:...} or {number_format:...} if you need fixed decimals.
test{avg:1,5:2,5}
Expected2
Actual2
Values are read as numbers regardless of comma or dot decimal separator: 1,5 and 2,5 become 1.5 and 2.5, averaging to 2. This matches how AA number fields store localized decimals.
test{avg:7:8:abc}
Expected5
Actual5
A non-numeric argument is read as 0 but still counts toward the divisor: (7+8+0)/3 is 5, not 7.5. Make sure every value is a real number, or filter blanks out first.
test{avg:[10,"",30]}
Expected20
Actual20
In the JSON-array form, empty-string entries are removed before averaging, so [10,"",30] averages only 10 and 30 to 20 (divided by 2, not 3). Zero is kept; only empty strings are dropped.