Skip to content

round

Description

Returns a number rounded to the nearest integer or to a specified number of decimal places. For example, 1.5 becomes 2 and 8.1 becomes 8.

Syntax

Like many functions in DataPrime, round supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

round(number: number, digits: number?): number
(number: number).round(digits: number?): number

Arguments

NameTypeRequiredDescription
numbernumbertrueThe value to round
digitsnumberfalseNumber of decimal places to round to. Defaults to 0 (whole numbers)

Example

Use case 1: Round averages for discrete counts

Compute the average number of online users and round to a whole number for clarity. Example: 569.5 becomes 570.

Use case 2: Round latency values for readability

When analyzing traces, average latency values may have long decimal places. Use round with 2 digits for cleaner results.

{
    "total_users_online": 1093
},
{
    "total_users_online": 942
},
{
    "total_users_online": 120
},
{
    "total_users_online": 123
}
aggregate round(avg(total_users_online)) as average_users_online
aggregate total_users_online.avg().round() as average_users_online

Output

{
    "average_users_online": 570
}