Skip to main content
Version: 1.4.0

Round

Arithmetic Data Analysis

Synopsis

Rounds numeric values to a specified precision.

Schema

- round:
field: <ident>
value: <string>
precision: <numeric>
description: <text>
if: <script>
ignore_failure: <boolean>
ignore_missing: <boolean>
on_failure: <processor[]>
on_success: <processor[]>
tag: <string>

Configuration

The following fields are used to define the processor:

FieldRequiredDefaultDescription
fieldY-Target field to store the rounded value
valueY-Value to round - can be a literal value or field reference
precisionY-Number of decimal places to round to
descriptionN-Explanatory note
ifN-Condition to run
ignore_failureNfalseContinue processing if rounding fails
ignore_missingNfalseSkip if referenced fields don't exist
on_failureN-Error handling processors
on_successN-Success handling processors
tagN-Identifier

Details

Rounds a numeric value to a specified number of decimal places and stores the result in the target field. The processor can extract values from existing fields or use literal numeric values.

note

Rounding uses half to even (banker's rounding) when the fractional part is exactly 0.5. This method is statistically unbiased and is the default for IEEE 754 floating-point operations.

The processor is useful for normalizing numeric data, improving readability, ensuring consistent precision across values, and preparing data for display or further calculations.

warning

Very large numbers might lose precision during floating-point operations. Consider using a different approach for values that require exact decimal representation, such as currency amounts in financial applications.

Examples

Basic

Rounding a value to the nearest integer...

{
"raw_value": 123.456
}
- round:
field: rounded_value
value: "raw_value"
precision: 0

rounds to whole number:

{
"raw_value": 123.456,
"rounded_value": 123
}

Precision

Rounding to two decimal places...

{
"metrics": {
"cpu_usage": 76.54321
}
}
- round:
field: metrics.cpu_usage_rounded
value: "metrics.cpu_usage"
precision: 2

provides consistent precision:

{
"metrics": {
"cpu_usage": 76.54321,
"cpu_usage_rounded": 76.54
}
}

In-Place

Updating a field with its rounded value...

{
"financial": {
"price": 19.9999
}
}
- round:
field: financial.price
value: "financial.price"
precision: 2

modifies the original field:

{
"financial": {
"price": 20.00
}
}

Batch

Applying consistent rounding to multiple values...

{
"statistics": {
"mean": 42.4382,
"median": 39.9951,
"std_dev": 5.6728
}
}
- round:
field: statistics.mean
value: "statistics.mean"
precision: 2
- round:
field: statistics.median
value: "statistics.median"
precision: 2
- round:
field: statistics.std_dev
value: "statistics.std_dev"
precision: 2

standardizes precision across all statistics:

{
"statistics": {
"mean": 42.44,
"median": 40.00,
"std_dev": 5.67
}
}

Formatting

Preparing values for user display...

{
"sensor": {
"temperature": 22.74659,
"humidity": 45.32185,
"pressure": 1013.25823
}
}
- round:
field: sensor.temperature_display
value: "sensor.temperature"
precision: 1
- round:
field: sensor.humidity_display
value: "sensor.humidity"
precision: 0
- round:
field: sensor.pressure_display
value: "sensor.pressure"
precision: 1

creates display-friendly values:

{
"sensor": {
"temperature": 22.74659,
"humidity": 45.32185,
"pressure": 1013.25823,
"temperature_display": 22.7,
"humidity_display": 45,
"pressure_display": 1013.3
}
}