Basic Rounding

Convert decimal numbers to nearest integers using the round() function

Query

flowchart LR; %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% repo{{Events}} 1>Augment Data] result{{Result Set}} repo --> 1 1 --> result
logscale
round(myvalue)

Introduction

The round() function rounds a number to the nearest integer (whole number) using standard math rules. Numbers greater than 0.5 are rounded up, numbers lower than 0.5 are rounded down.

Example incoming data might look like this:

@timestampmyvalue
2025-11-05T10:00:00Z3.2
2025-11-05T10:00:01Z3.7
2025-11-05T10:00:02Z4.5
2025-11-05T10:00:03Z4.51
2025-11-05T10:00:04Z5.49
2025-11-05T10:00:05Z5.5
2025-11-05T10:00:06Z-3.2
2025-11-05T10:00:07Z-3.5
2025-11-05T10:00:08Z-3.7

Step-by-Step

  1. Starting with the source repository events.

  2. flowchart LR; %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% repo{{Events}} 1>Augment Data] result{{Result Set}} repo --> 1 1 --> result style 1 fill:#ff0000,stroke-width:4px,stroke:#000;
    logscale
    round(myvalue)

    Rounds the number in myvalue.

  3. Event Result set.

Summary and Results

The query is used to round a floating point number to the nearest integer. Rounding is used to simplify numbers. The benefit to rounding is that it returns numbers that are easier to work with.

Sample output from the incoming example data:

@timestampmyvalue
2025-11-05T10:00:00Z3
2025-11-05T10:00:01Z4
2025-11-05T10:00:02Z5
2025-11-05T10:00:03Z5
2025-11-05T10:00:04Z5
2025-11-05T10:00:05Z6
2025-11-05T10:00:06Z-3
2025-11-05T10:00:07Z-3
2025-11-05T10:00:08Z-4

Note that the output demonstrates LogScale's rounding behavior where positive numbers are rounded up when the decimal is .5 or greater, and negative numbers follow the "round half away from zero" rule (unless you use how=floor).

Note

To format a number, or round to a specific decimal accuracy, use format(). See Rounding to n Decimal Places.