Working with Types
Understanding data types is essential for writing correct formulas. Precision Bridge formulas support a rich set of Python data types and provide functions for converting between them.
Available Data Types
Formulas can work with the following data types:
| Type | Examples | Description |
|---|---|---|
str |
'hello', "world" |
Text strings |
int |
42, -7, 0 |
Whole numbers |
float |
3.14, -0.5 |
Floating-point numbers |
Decimal |
Numeric literals with decimals | High-precision decimal numbers |
bool |
True, False |
Boolean values |
None |
None, Null |
Represents a missing or null value |
list |
[1, 2, 3] |
Ordered, mutable collections |
dict |
{'key': 'value'} |
Key-value mappings |
tuple |
(1, 2, 3) |
Ordered, immutable collections |
set |
{1, 2, 3} |
Unordered collections of unique values |
Numeric Precision
When you write a numeric literal with a decimal point (e.g., 3.14), it is stored as a Decimal rather than a float. This preserves precision during arithmetic -- an important detail when working with financial data or identifiers.
int + intproducesintint + floatproducesfloatint + DecimalproducesDecimalfloat + DecimalproducesDecimal
Type Conversion Functions
Use these built-in functions to convert values between types:
| Function | Description | Example |
|---|---|---|
str() |
Convert to string | str(42) returns '42' |
int() |
Convert to integer | int('7') returns 7 |
float() |
Convert to floating-point number | float('3.14') returns 3.14 |
bool() |
Convert to boolean | bool(1) returns True |
list() |
Convert iterable to list | list((1,2,3)) returns [1, 2, 3] |
dict() |
Create dictionary from key-value pairs | dict([('a', 1)]) returns {'a': 1} |
set() |
Convert iterable to set (unique values) | set([1,1,2]) returns {1, 2} |
tuple() |
Convert iterable to tuple | tuple([1,2]) returns (1, 2) |
Type Checking
You can inspect types at runtime with these functions:
type([priority])
Returns the type of the value, e.g., <class 'int'>.
isinstance([priority], int)
Returns True if the value is an instance of the specified type, False otherwise.
Type Coercion Rules
Precision Bridge does not automatically convert between incompatible types. You must convert explicitly when mixing types:
String + Integer will raise an error:
[name] + [priority]
This fails if name is a string and priority is an integer. Instead, convert explicitly:
[name] + str([priority])
Integer + Float produces Float:
[count] + 0.5
If count is an integer, the result is a float.
Integer + Decimal produces Decimal:
[quantity] + 1
If quantity is a Decimal value from the source system, the result remains a Decimal.
Working with None Values
Source fields that have no value will be None. Always account for this possibility to avoid errors:
Safe string conversion:
str([field]) if [field] is not None else ''
Providing a default value:
[email] if [email] is not None else 'no-email@example.com'
Checking for None explicitly:
[assigned_to] is None
[assigned_to] is not None
Date and Time Types
The following date/time types are available as built-in constructors:
| Type | Example |
|---|---|
datetime |
datetime(2024, 6, 15, 10, 30, 0) |
date |
date(2024, 6, 15) |
time |
time(10, 30, 0) |
timedelta |
timedelta(days=30) |
You can use datetime.now() to get the current date and time, date.today() to get today's date, and perform date arithmetic using timedelta:
datetime.now() - timedelta(days=7)
This returns a datetime representing exactly one week ago.
Important: Dates in filter conditions. When building standard filter conditions that compare against date or datetime fields, always use the
date()ordatetime()constructors to create date values. Do not pass raw date strings — PB needs proper date objects to translate them into the source system's date format.```
Correct — use date()/datetime() constructors:
datetime.now() - timedelta(days=30) date(2024, 1, 1)
Incorrect — raw strings will not be translated correctly:
'2024-01-01' ```
For the full date/datetime reference, see: date(), datetime(), timedelta().
Practical Examples
Convert a string field to an integer
int([priority])
Useful when a source system stores numeric values as strings.
Convert an integer to a string for concatenation
'Record ID: ' + str([sys_id])
Joins the text Record ID: with the string representation of sys_id.
Handle None with a default value
str([description]) if [description] is not None else 'No description provided'
Returns the description as a string, or a default message if the field is null.
Round a decimal value
round(float([price]), 2)
Converts price to a float and rounds to two decimal places.
Check if a value is a string
isinstance([value], str)
Returns True if the field contains a string, False otherwise. Useful for conditional logic when field types may vary.
Next Steps
- Learn string manipulation techniques in String Operations
- Explore conditional expressions in Conditional Logic
- See all available built-in functions in Available Built-in Functions
- See Common Formula Patterns for 30 ready-to-use formula examples
- For date/datetime details: date(), datetime(), timedelta()
Comments
0 comments
Please sign in to leave a comment.