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!

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...