Comments and answers for "Can I use modulus in Splunk to extract the decimal portion (only) of a result?"
https://answers.splunk.com/answers/562679/can-i-use-modulus-in-splunk-to-extract-the-decimal.html
The latest comments and answers for the question "Can I use modulus in Splunk to extract the decimal portion (only) of a result?"Comment by niketnilay on niketnilay's comment
https://answers.splunk.com/comments/562141/view.html
@nittalasub, I have converted @DalJeanis' comment to answer. Please accept to mark this question as answered. Kindly also up vote other comments that helped.Mon, 14 Aug 2017 05:49:03 GMTniketnilayComment by nittalasub on nittalasub's answer
https://answers.splunk.com/comments/562138/view.html
@Daljeanis -- thank you so much ! :) that helped me to extract decimals from floating point numbers.
special thanks to Nike !Mon, 14 Aug 2017 05:12:06 GMTnittalasubComment by DalJeanis on DalJeanis's comment
https://answers.splunk.com/comments/562693/view.html
3%7 is 3, so (3%7)/7 = 3/7
The formula only fails (potentially)for negative numbers.
Depending on implementation -3%7 can be considered to be either -3 or +4. Those two numbers are identities in mod 7 ring theory and whatever the other relevant branches of discrete math are.... but not when you are calculating real world stuff.
So, for safety, if I couldn't run a quick test, I'd end up coding that as...
decimal=round(if(X<0, -(-X%Y)/Y,(X%Y)/Y),somenumber)Mon, 14 Aug 2017 03:19:44 GMTDalJeanisComment by niketnilay on niketnilay's answer
https://answers.splunk.com/comments/562692/view.html
@DalJeanis, I need to take not just Splunk lessons from you but maths also :)
How about dividend < divisor? like (3/7)?Mon, 14 Aug 2017 02:40:35 GMTniketnilayAnswer by DalJeanis
https://answers.splunk.com/answering/562140/view.html
@niketnilay - Great demo, but modulo arithmetic does simplify the calculation down to ..
... | eval decimal=(7%2)/2Sun, 13 Aug 2017 20:40:38 GMTDalJeanisComment by DalJeanis on DalJeanis's comment
https://answers.splunk.com/comments/562121/view.html
@jkat54 - correct, but one more step to get the requested answer...
... | eval decimal=(7%2)/2Sun, 13 Aug 2017 20:38:18 GMTDalJeanisAnswer by niketnilay
https://answers.splunk.com/answering/562089/view.html
Following is the run anywhere search. While modular division is possible, you are actually looking just to extract decimal places.
| makeresults
| eval dividend=7
| eval divisor=2
| eval value=dividend/divisor
| eval remainder=dividend%divisor
| eval quotient=replace(value,"(\d+).(\d+)","\1")
| eval decimal=replace(value,"(\d+)(\.\d+)","0\2")
| table dividend divisor value remainder quotient decimal
Following are the results:
dividend divisor value remainder quotient decimal
7 2 3.5 1 3 0.5Sun, 13 Aug 2017 05:18:44 GMTniketnilayComment by jkat54 on jkat54's answer
https://answers.splunk.com/comments/562080/view.html
So it would look like this?
... | eval remainder=7%2
Correct? I've never done it before.Sun, 13 Aug 2017 03:08:16 GMTjkat54Answer by richgalloway
https://answers.splunk.com/answering/562072/view.html
Splunk does support the modulus (%) operator.Sat, 12 Aug 2017 23:04:04 GMTrichgalloway