<?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: Typecast an integer to a float? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Typecast-an-integer-to-a-float/m-p/407999#M167272</link>
    <description>&lt;P&gt;Splunk by default rounds values within eval calculations to a precision that it thinks is appropriate. Thereby the resulting precision is limited by the precision of the least-precise operand.&lt;/P&gt;

&lt;P&gt;To make it more precise let's focuse on the "&lt;STRONG&gt;(1.0-b)&lt;/STRONG&gt;" part of your calculation:&lt;/P&gt;

&lt;P&gt;Search:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;| makeresults | eval b=.15 | eval c_part_optionA=(1.0-b) | eval c_part_optionB=(1.00-b) | eval c_part_optionC=exact((1.0-b)) | table b c_*&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;Results:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;b  c_part_optionA  c_part_optionB  c_part_optionC&lt;BR /&gt;
    0.15    0.9 0.85    0.85&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;So the solution to your problem is using the &lt;STRONG&gt;exact()&lt;/STRONG&gt; function as dokumented in the &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.0/SearchReference/MathematicalFunctions#exact.28X.29" target="_blank"&gt;SearchReference&lt;/A&gt;.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval a=1024.0 | eval b=.15 | eval c=exact(a*(1.0-b)) | table a b c
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This behaviour can be unexpected unexpected by an user. In my opinion the decision to do it that way is suboptimal and the behaviour is not documented verry well.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 21:29:43 GMT</pubDate>
    <dc:creator>back2root</dc:creator>
    <dc:date>2020-09-29T21:29:43Z</dc:date>
    <item>
      <title>Typecast an integer to a float?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Typecast-an-integer-to-a-float/m-p/407998#M167271</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval a=1024.0 | eval b=.15 | eval c=a*(1.0-b) | table a b c
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;gives&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;a   b   c
1024.0  0.15    870
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There are no integers, only floats. So why does Splunk typecast "c" to an int? It's not like it typecasts 870.0 to an int (which would still be unacceptable) it does it to 870.4.&lt;/P&gt;

&lt;P&gt;Also, how do I fix this so that 870.4 is displayed?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 23:20:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Typecast-an-integer-to-a-float/m-p/407998#M167271</guid>
      <dc:creator>nick405060</dc:creator>
      <dc:date>2018-10-03T23:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: Typecast an integer to a float?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Typecast-an-integer-to-a-float/m-p/407999#M167272</link>
      <description>&lt;P&gt;Splunk by default rounds values within eval calculations to a precision that it thinks is appropriate. Thereby the resulting precision is limited by the precision of the least-precise operand.&lt;/P&gt;

&lt;P&gt;To make it more precise let's focuse on the "&lt;STRONG&gt;(1.0-b)&lt;/STRONG&gt;" part of your calculation:&lt;/P&gt;

&lt;P&gt;Search:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;| makeresults | eval b=.15 | eval c_part_optionA=(1.0-b) | eval c_part_optionB=(1.00-b) | eval c_part_optionC=exact((1.0-b)) | table b c_*&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;Results:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;b  c_part_optionA  c_part_optionB  c_part_optionC&lt;BR /&gt;
    0.15    0.9 0.85    0.85&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;So the solution to your problem is using the &lt;STRONG&gt;exact()&lt;/STRONG&gt; function as dokumented in the &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.0/SearchReference/MathematicalFunctions#exact.28X.29" target="_blank"&gt;SearchReference&lt;/A&gt;.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval a=1024.0 | eval b=.15 | eval c=exact(a*(1.0-b)) | table a b c
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This behaviour can be unexpected unexpected by an user. In my opinion the decision to do it that way is suboptimal and the behaviour is not documented verry well.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:29:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Typecast-an-integer-to-a-float/m-p/407999#M167272</guid>
      <dc:creator>back2root</dc:creator>
      <dc:date>2020-09-29T21:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: Typecast an integer to a float?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Typecast-an-integer-to-a-float/m-p/408000#M167273</link>
      <description>&lt;P&gt;It is rounded to an integer. If you want to control, use the following function.&lt;/P&gt;

&lt;P&gt;ex.&lt;BR /&gt;
 | makeresults | eval a=1024.0 | eval b=.15 | eval c=round(a*(1.0-b),2) | table a b c&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 01:55:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Typecast-an-integer-to-a-float/m-p/408000#M167273</guid>
      <dc:creator>HiroshiSatoh</dc:creator>
      <dc:date>2018-10-04T01:55:41Z</dc:date>
    </item>
    <item>
      <title>Re: Typecast an integer to a float?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Typecast-an-integer-to-a-float/m-p/408001#M167274</link>
      <description>&lt;P&gt;Thanks. Definitely documented poorly, nothing in a Google search, and for something so basic too&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 16:06:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Typecast-an-integer-to-a-float/m-p/408001#M167274</guid>
      <dc:creator>nick405060</dc:creator>
      <dc:date>2018-10-04T16:06:23Z</dc:date>
    </item>
  </channel>
</rss>

