Splunk Search

## How to round up a number and avoid infinite zeros?

Ultra Champion

I am trying to round UP numbers one decimal to the left whenever its, for example:
10510 ---> 11000
10499 ---> 10000
read the following answers, but cant apply those as they are rounding down, also, seems like the `ciel` function is depreciated?

``````| makeresults count=1
| eval data = "10510,20010.11,10999.99,10500,10499,10000,10001,501,21"
| makemv delim="," data
| mvexpand data
| eval rounded_1 = round(data, -1)
| eval rounded_2 = round(data, -2)
| eval rounded_3 = round(data, -3)
| eval using_floor = floor(data)
``````

How can I avoid the zeros? see screenshot:

Tags (3)
1 Solution
SplunkTrust

The ceil or ceiling function but now we just have ceiling.

Your rounding_3 didn't work for me in Splunk 6.2x. I thought function sigfig would work but that also doesn't work past 2 decimal digits. I found the expression (workaround) I used in rounding_custom worked for me. Give this a try.

``````| gentimes start=-1
| eval data = "10550,20010.11,10999.99,10500,10499,10000,10001,501,21" | table data
| makemv delim="," data
| mvexpand data
| eval rounded_1 = round(data, -1)
| eval rounded_2 = round(data, -2)
| eval rounding_sigfig = sigfig(data*1.000)
| eval rounding_custom=round(data/1000)*1000
| eval using_floor = ceil(data)
``````
SplunkTrust

The ceil or ceiling function but now we just have ceiling.

Your rounding_3 didn't work for me in Splunk 6.2x. I thought function sigfig would work but that also doesn't work past 2 decimal digits. I found the expression (workaround) I used in rounding_custom worked for me. Give this a try.

``````| gentimes start=-1
| eval data = "10550,20010.11,10999.99,10500,10499,10000,10001,501,21" | table data
| makemv delim="," data
| mvexpand data
| eval rounded_1 = round(data, -1)
| eval rounded_2 = round(data, -2)
| eval rounding_sigfig = sigfig(data*1.000)
| eval rounding_custom=round(data/1000)*1000
| eval using_floor = ceil(data)
``````
Ultra Champion

thanks @somesoni!
up voting as i find this `round(data/1000)*1000` very useful.
however, if have a 6 (or greater) digits number, the `rounding_custom` wont work and seems like ill have to adjust the `rounding_custom` rule accordingly.
thanks again

SplunkTrust

Do you've example data for those 6 or higher digit with expected output?

Ultra Champion

yes, can be anywhere as the value is sum of counts it can range form single digits to rare items all the way to 9 digits, the highest ive seen so far in this data set

SplunkTrust

So you want to dynamically round based on 2nd digit from left. Give this a try (should work for any length of data)

``````| gentimes start=-1
| eval data = "123456,1234567,87654321,987654321,123456789,10510,20010.11,10999.99,10500,10499,10000,10001,501,552,21,29" | table data
| makemv delim="," data
| mvexpand data | eval mf=pow(10,len(tostring(round(data)))-1)
| eval rounding_custom1=round(data/mf)*mf
``````
Ultra Champion

@somesoni2, i see your trick there with the multiplying factor, love it.
ill take it as an answer as it works. still puzzled why the `round(X, -3)` wont work... any idea?
thanks again!

Get Updates on the Splunk Community!

#### What’s New in Splunk Cloud Platform 9.1.2308?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2308! Analysts can ...

#### Index This | Why do they call it hyper text?

November 2023 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

#### State of Splunk Careers 2023: Career Resilience and the Continued Value of Splunk

For the past three years, Splunk has partnered with Enterprise Strategy Group to conduct a survey that gauges ...