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!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...