Splunk Search

Convert String to Integer

nikhilmehra79
Path Finder

I have extracted a value out of expression but seems like it is still treated as String not integer and i cant do any math on it.
For example before applying extraction the variable was : "0.05 %" - i extracted it to 0.05 but when i do any math on it it comes with blank value - as if splunk is not considering it as integer but as string - is that possible?

Tags (3)
1 Solution

lguinn2
Legend

You can fix that -

| eval myInt = tonumber(myString)

View solution in original post

enno
Explorer

Technically, this gives you a numeric not an integer though, which seems to be what the OP wanted. For those who come here looking for actual integers you likely need to eval your expression/field with round(), floor() or ceil() depending what sort of integer you need. For example, if you were calculating a row number from a sequence number you'd need something like:

... | eval row=floor(seqno % numcols) | ...

See http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions#floor for more details.

lguinn2
Legend

You can fix that -

| eval myInt = tonumber(myString)
Get Updates on the Splunk Community!

Enter the Splunk Community Dashboard Challenge for Your Chance to Win!

The Splunk Community Dashboard Challenge is underway! This is your chance to showcase your skills in creating ...

.conf24 | Session Scheduler is Live!!

.conf24 is happening June 11 - 14 in Las Vegas, and we are thrilled to announce that the conference catalog ...

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...