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!

Technical Workshop Series: Splunk Data Management and SPL2 | Register here!

Hey, Splunk Community! Ready to take your data management skills to the next level? Join us for a 3-part ...

Spotting Financial Fraud in the Haystack: A Guide to Behavioral Analytics with Splunk

In today's digital financial ecosystem, security teams face an unprecedented challenge. The sheer volume of ...

Solve Problems Faster with New, Smarter AI and Integrations in Splunk Observability

Solve Problems Faster with New, Smarter AI and Integrations in Splunk Observability As businesses scale ...