{compare:val1:val2}

Description

Compares two values and returns a single letter: E if they are equal, G if the first value is greater, or L if the first value is less. Comparison is numeric when both values look like numbers, otherwise it is done as text (character by character). On its own compare prints only the letter; in practice you wrap it in ifeq or switch to turn E/G/L into readable words, markup, or a sort decision. Parameters are trimmed of surrounding spaces. The expression is never cached.

Parameters

val1 required

The first value to compare. Compared numerically when both values look like numbers, otherwise as text. Leading and trailing spaces are trimmed.

val2 required

The second value to compare against the first. Same numeric-or-text rule and trimming as val1.

Examples

test{compare:7:7}
ExpectedE
ActualE
When the two values are equal the result is E. Compare itself never prints a word - it returns one of three single letters: E (equal), G (first is greater), L (first is less).
test{compare:5:3}
ExpectedG
ActualG
G means the first value is greater than the second.
test{compare:3:5}
ExpectedL
ActualL
L means the first value is less than the second. So the three outcomes are E, G and L for equal, greater and less.
test{ifeq:{compare:5:3}:G:greater:L:less:E:equal}
Expectedgreater
Actualgreater
The usual real-world use: feed the E/G/L letter into ifeq (or switch) to pick readable text or markup. Here compare returns G, and ifeq maps G to the word greater.
test{compare:100:20}
ExpectedG
ActualG
Comparison is numeric when both values look like numbers, so 100 is correctly greater than 20. A plain text sort would wrongly put 100 before 20 (because 1 is before 2).
test{compare:apple:banana}
ExpectedL
ActualL
When the values are not numbers they are compared as text, character by character. apple comes before banana, so the first value is less (L).
test{switch({compare:2024-03-15:2024-01-01})G:later:L:earlier:same}
Expectedlater
Actuallater
Comparing ISO dates (YYYY-MM-DD) works because they sort correctly as text. Here the first date is later, so compare returns G and switch prints later. Use the switch(...) paren form so the colons inside the dates are not read as parameter separators.