Round off BigDecimal Values
| Definition: | round(value: BigDecimal, no_of_places: int) → BigDecimal
|
| Description: | Round off a java.math.BigDecimal value to your desired decimal place. |
| Parameters: | - value: The java.math.BigDecimal value to be rounded off. - no_of_places: The number of places to which the BigDecimal value is to be rounded off. |
| Returns: | The rounded off decimal value. |
The following script rounds off the value in the <variable > field to the number of places specified by <no_of_places > and returns the rounded-off value in the <rounded_variable > field.
Note: Replace the placeholder values in the script with your own.
from io.hevo.api import Event
from io.hevo.api import Utils
def transform(event):
eventName = event.getEventName()
properties = event.getProperties()
properties['<rounded_variable>'] = Utils.round(properties['<variable>'], <no_of_places>)
return event
Sample Transformation
The following script demonstrates how the round function can be used. It rounds off the BigDecimal value in agent_id to two decimal places and writes the rounded-off value in the agent_id2 field.
from io.hevo.api import Event
from io.hevo.api import Utils
def transform(event):
eventName = event.getEventName()
properties = event.getProperties()
properties['agent_id2'] = Utils.round(properties['agent_id'], 2)
return event
Sample Output
The value of agent_id, 4.457234, is rounded off to two decimal places as 4.46 and assigned to the agent_id2 field.

See Also
- Supported Python Modules and Functions
- Examples of Python Code-based Transformations
- Transformation Methods in the Event Class
Last updated on Mar 05, 2024