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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...