<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Eval round gives inconsistent half-rounding results in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Eval-round-gives-inconsistent-half-rounding-results/m-p/433104#M166920</link>
    <description>&lt;P&gt;Good explanation of the problem and a clear workaround based on that. I had figured this would probably be related to a floating-points somehow, but since PHP doesn't have this problem (but definitely is prone to floating-point number inaccuracies) I thought there might be another explanation... super interesting that Python gives the same results.&lt;/P&gt;

&lt;P&gt;Regardless, using round with a negative value hadn't occurred to me, and provides a clear and relatively readable method of ensuring reliable results. Great stuff!&lt;/P&gt;</description>
    <pubDate>Thu, 25 Oct 2018 23:29:20 GMT</pubDate>
    <dc:creator>pentwist</dc:creator>
    <dc:date>2018-10-25T23:29:20Z</dc:date>
    <item>
      <title>Eval round gives inconsistent half-rounding results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-round-gives-inconsistent-half-rounding-results/m-p/433100#M166916</link>
      <description>&lt;P&gt;I tried setting up a Splunk alert to check for inconsistencies between a rounded total and a raw total, but the alert has been giving false positives at random intervals because Splunk's &lt;CODE&gt;round&lt;/CODE&gt; function doesn't seem to applying a consistent half-rounding rule. A clear example of this is if the following query is run:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;*
| eval rounded_amount_22=round(22.275,2)
| eval rounded_amount_21=round(21.275,2)
| eval rounded_amount_20=round(20.275,2)
| eval rounded_amount_19=round(19.275,2)
| eval rounded_amount_18=round(18.275,2)
| eval rounded_amount_17=round(17.275,2)
| eval rounded_amount_16=round(16.275,2)
| eval rounded_amount_15=round(15.275,2)
| eval rounded_amount_14=round(14.275,2)
| eval rounded_amount_13=round(13.275,2)
| eval rounded_amount_12=round(12.275,2)
| eval rounded_amount_11=round(11.275,2)
| eval rounded_amount_10=round(10.275,2)
| head 1
| table
rounded_amount_10,
rounded_amount_11,
rounded_amount_12,
rounded_amount_13,
rounded_amount_14,
rounded_amount_15,
rounded_amount_16,
rounded_amount_17,
rounded_amount_18,
rounded_amount_19,
rounded_amount_20,
rounded_amount_21,
rounded_amount_22
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If Splunk was using half-up, half-down, or banker's rounding, I'd expect to see consistency in the results, but I just don't see a pattern in what I get back:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rounded_amount_10: 10.28
rounded_amount_11: 11.28
rounded_amount_12: 12.28
rounded_amount_13: 13.28
rounded_amount_14: 14.28
rounded_amount_15: 15.28
rounded_amount_16: 16.27
rounded_amount_17: 17.27
rounded_amount_18: 18.27
rounded_amount_19: 19.27
rounded_amount_20: 20.27
rounded_amount_21: 21.28
rounded_amount_22: 22.28
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In particular, every rounding scheme I know of should treat &lt;CODE&gt;10.275&lt;/CODE&gt; and &lt;CODE&gt;20.275&lt;/CODE&gt; the same - but as shown in the above list, Splunk is rounding &lt;EM&gt;up&lt;/EM&gt; to &lt;CODE&gt;10.28&lt;/CODE&gt; and &lt;EM&gt;down&lt;/EM&gt; to &lt;CODE&gt;20.27&lt;/CODE&gt;. I just don't see a pattern in it.&lt;/P&gt;

&lt;P&gt;I've also tried wrapping the &lt;CODE&gt;round&lt;/CODE&gt; function in &lt;CODE&gt;exact&lt;/CODE&gt;, but that doesn't change the results.&lt;/P&gt;

&lt;P&gt;What's going on here? Is it possible for this query to return consistent half-rounding results?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 22:52:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-round-gives-inconsistent-half-rounding-results/m-p/433100#M166916</guid>
      <dc:creator>pentwist</dc:creator>
      <dc:date>2018-10-22T22:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: Eval round gives inconsistent half-rounding results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-round-gives-inconsistent-half-rounding-results/m-p/433101#M166917</link>
      <description>&lt;P&gt;Just tested something similar in Python and got similar results&lt;/P&gt;

&lt;P&gt;x = round(15.275, 2)&lt;BR /&gt;
print(x)&lt;BR /&gt;
y = round(17.275, 2)&lt;BR /&gt;
print(y)&lt;/P&gt;

&lt;P&gt;produces&lt;/P&gt;

&lt;P&gt;15.28&lt;BR /&gt;
17.27&lt;/P&gt;

&lt;P&gt;Is this down to Floating point inaccuracy?&lt;/P&gt;</description>
      <pubDate>Thu, 25 Oct 2018 15:47:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-round-gives-inconsistent-half-rounding-results/m-p/433101#M166917</guid>
      <dc:creator>msivill_splunk</dc:creator>
      <dc:date>2018-10-25T15:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: Eval round gives inconsistent half-rounding results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-round-gives-inconsistent-half-rounding-results/m-p/433102#M166918</link>
      <description>&lt;P&gt;Playing around with this some more the following works&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval rounded_amount_22=round(22.275*1000,-1)/1000
| eval rounded_amount_21=round(21.275*1000,-1)/1000
| eval rounded_amount_20=round(20.275*1000,-1)/1000
| eval rounded_amount_19=round(19.275*1000,-1)/1000
| eval rounded_amount_18=round(18.275*1000,-1)/1000
| eval rounded_amount_17=round(17.275*1000,-1)/1000
| eval rounded_amount_16=round(16.275*1000,-1)/1000
| eval rounded_amount_15=round(15.275*1000,-1)/1000
| eval rounded_amount_14=round(14.275*1000,-1)/1000
| eval rounded_amount_13=round(13.275*1000,-1)/1000
| eval rounded_amount_12=round(12.275*1000,-1)/1000
| eval rounded_amount_11=round(11.275*1000,-1)/1000
| eval rounded_amount_10=round(10.275*1000,-1)/1000
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The challenge here I think is the way computers hold floating numbers. &lt;A href="http://effbot.org/pyfaq/why-are-floating-point-calculations-so-inaccurate.htm"&gt;http://effbot.org/pyfaq/why-are-floating-point-calculations-so-inaccurate.htm&lt;/A&gt; gives some further background to the problem.&lt;/P&gt;

&lt;P&gt;The above scales up the number to a whole number performs the round then reduces it back to a float.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Oct 2018 15:58:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-round-gives-inconsistent-half-rounding-results/m-p/433102#M166918</guid>
      <dc:creator>msivill_splunk</dc:creator>
      <dc:date>2018-10-25T15:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: Eval round gives inconsistent half-rounding results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-round-gives-inconsistent-half-rounding-results/m-p/433103#M166919</link>
      <description>&lt;P&gt;Here's a workaround... just add a tiny smidge to the thing being rounded.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
 | eval smidge=0.000000000001
 | eval rounded_amount_16R=round(16.275,2)
 | eval rounded_amount_15R=round(15.275,2)
 | eval rounded_amount_16S=round(16.275+smidge,2)
 | eval rounded_amount_15S=round(15.275+smidge,2)
 | table smidge  rounded_amount_*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want to see output in table form, you can do this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | untable smidge fieldname fieldvalue
 | rex field=fieldname "(?&amp;lt;test&amp;gt;rounded_amount_\d\d)(?&amp;lt;method&amp;gt;\w)"
 | chart first(fieldvalue) by test method
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Oct 2018 17:21:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-round-gives-inconsistent-half-rounding-results/m-p/433103#M166919</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2018-10-25T17:21:26Z</dc:date>
    </item>
    <item>
      <title>Re: Eval round gives inconsistent half-rounding results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-round-gives-inconsistent-half-rounding-results/m-p/433104#M166920</link>
      <description>&lt;P&gt;Good explanation of the problem and a clear workaround based on that. I had figured this would probably be related to a floating-points somehow, but since PHP doesn't have this problem (but definitely is prone to floating-point number inaccuracies) I thought there might be another explanation... super interesting that Python gives the same results.&lt;/P&gt;

&lt;P&gt;Regardless, using round with a negative value hadn't occurred to me, and provides a clear and relatively readable method of ensuring reliable results. Great stuff!&lt;/P&gt;</description>
      <pubDate>Thu, 25 Oct 2018 23:29:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-round-gives-inconsistent-half-rounding-results/m-p/433104#M166920</guid>
      <dc:creator>pentwist</dc:creator>
      <dc:date>2018-10-25T23:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: Eval round gives inconsistent half-rounding results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-round-gives-inconsistent-half-rounding-results/m-p/433105#M166921</link>
      <description>&lt;P&gt;Great, glad this works for you and thank you for the up vote.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 08:13:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-round-gives-inconsistent-half-rounding-results/m-p/433105#M166921</guid>
      <dc:creator>msivill_splunk</dc:creator>
      <dc:date>2018-10-26T08:13:47Z</dc:date>
    </item>
  </channel>
</rss>

