Type Conversions
The str(), int(), float(), and bool() built-in functions convert values between types. Explicit conversion is required when mixing types in formulas — Precision Bridge does not implicitly coerce types.
str()
Converts any value to its string representation.
str(42) # '42'
str(3.14) # '3.14'
str(True) # 'True'
str(None) # 'None'
str([priority]) # Converts field to string
Common use: Concatenating numeric fields with text.
'Priority: ' + str([priority])
int()
Converts a value to an integer. Truncates decimal portions (does not round).
int('42') # 42
int(3.9) # 3 (truncated, not rounded)
int(True) # 1
int(False) # 0
int([score]) # Converts field to integer
Common use: Converting string fields that contain numeric values.
int([priority]) if [priority] is not None else 0
Note:
int()raises an error if the string is not a valid integer. Always check for None first.
float()
Converts a value to a floating-point number.
float('3.14') # 3.14
float(42) # 42.0
float([temperature]) # Converts field to float
Common use: Numeric calculations that need decimal precision.
round(float([price]) * 1.1, 2)
bool()
Converts a value to a boolean. The following values are falsy (convert to False):
None,False,0,0.0,''(empty string),[](empty list),{}(empty dict),set()(empty set)
Everything else is truthy (converts to True).
bool(0) # False
bool(1) # True
bool('') # False
bool('hello') # True
bool(None) # False
bool([]) # False
Common use: Checking if a field has a meaningful value.
'Yes' if bool([active]) else 'No'
Handling None Safely
Always guard against None before converting, since int(None) and float(None) raise errors:
int([field]) if [field] is not None else 0
float([field]) if [field] is not None else 0.0
str([field]) if [field] is not None else ''
Or use the if_null() function:
int(if_null([field], '0'))
Related Documentation
- Working with Types — Data types and type coercion rules
- if_null — Provide defaults for null values
- Available Built-in Functions — Complete built-in function reference
Comments
0 comments
Please sign in to leave a comment.