Math Functions
Built-in math functions available in formulas for numeric calculations.
abs()
Returns the absolute value of a number.
abs(-5) # 5
abs([temperature_diff]) # Always positive
min() / max()
Return the smallest or largest of the given arguments, or of an iterable.
min(3, 1, 4, 1, 5) # 1
max(3, 1, 4, 1, 5) # 5
min([score1], [score2]) # Smaller of two fields
max([quota], 0) # Ensure non-negative
With a list:
min([10, 20, 30]) # 10
max([int(x) for x in [scores].split(',')]) # Max from CSV field
round()
Rounds a number to the specified number of decimal places.
round(3.14159) # 3
round(3.14159, 2) # 3.14
round(float([price]), 2) # Round field to 2 decimals
sum()
Sums all items in an iterable.
sum([10, 20, 30]) # 60
sum([int(x) for x in [scores].split(',')]) # Sum from CSV field
pow()
Raises a number to a power. Equivalent to the ** operator.
pow(2, 10) # 1024
pow([base], [exponent]) # Field-based
range()
Generates a sequence of integers. Returns a range object (convert to list if needed).
list(range(5)) # [0, 1, 2, 3, 4]
list(range(1, 6)) # [1, 2, 3, 4, 5]
list(range(0, 10, 2)) # [0, 2, 4, 6, 8]
len()
Returns the length of a string, list, dictionary, or other collection.
len('hello') # 5
len([1, 2, 3]) # 3
len([description]) # Character count of field
len([tags].split(',')) # Number of comma-separated tags
sorted() / reversed()
Return new sorted or reversed sequences.
sorted([3, 1, 4, 1, 5]) # [1, 1, 3, 4, 5]
sorted([tags].split(',')) # Alphabetical sort
sorted(my_list, reverse=True) # Descending
list(reversed([1, 2, 3])) # [3, 2, 1]
Related Documentation
- Available Built-in Functions — Complete built-in function reference
- Working with Types — Numeric precision and type coercion
- Lists, Dictionaries, and Indexing — Working with collections
Comments
0 comments
Please sign in to leave a comment.