<?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: A calculation precision issue with ABAP. in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/a-calculation-precision-issue-with-abap/m-p/634220#M26734</link>
    <description>&lt;P&gt;&lt;/P&gt;
  &lt;P&gt;If you read the ABAP documentation, you'll understand the reason (with 14 digits after the decimal point, 37/144 is stored as an unprecise value of 0.25694444444444, it can't store the fact that there's an endless sequence of "4", so because of the missing "4" from the 15th position, if you multiply by 37 you get 39.77499999999931).&lt;/P&gt;
  &lt;P&gt;But as I'm not expert with C++/java, I can't explain how these languages can get the right result because I thought that the "double" storage was the same logic as for ABAP type "F" (binary floating point on 8 bytes, with same mantissa and so on). Of course, here you are testing the decimal floating point types, which are different from "double".&lt;/P&gt;</description>
    <pubDate>Wed, 18 Apr 2018 04:45:13 GMT</pubDate>
    <dc:creator>Sandra_Rossi</dc:creator>
    <dc:date>2018-04-18T04:45:13Z</dc:date>
    <item>
      <title>A calculation precision issue with ABAP.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/a-calculation-precision-issue-with-abap/m-p/634218#M26732</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;I've met a question about division and multiply. Please see the following java codes.&lt;/P&gt;
  &lt;P&gt;double a = 154.8, b = 37, c = 144; &lt;/P&gt;
  &lt;P&gt; double d = b/c; &lt;/P&gt;
  &lt;P&gt; d = a * d; &lt;/P&gt;
  &lt;P&gt;The result of 'd' is 39.775&lt;/P&gt;
  &lt;P&gt;However, I've made a similar program in ABAP, see below.&lt;/P&gt;
  &lt;P&gt;data lv_decfloat34_1 type decfloat34.&lt;BR /&gt; data lv_decfloat34_2 type decfloat34.&lt;BR /&gt; data lv_decfloat34_3 type decfloat34.&lt;BR /&gt; data lv_decfloat34_4 type decfloat34.&lt;BR /&gt; &lt;BR /&gt; lv_decfloat34_1 = '154.8'.&lt;BR /&gt; lv_decfloat34_2 = 37.&lt;BR /&gt; lv_decfloat34_3 = 144.&lt;BR /&gt; &lt;BR /&gt; lv_decfloat34_4 = lv_decfloat34_2 / lv_decfloat34_3.&lt;BR /&gt; lv_decfloat34_4 = lv_decfloat34_1 * lv_decfloat34_4.&lt;BR /&gt;* result is 39,77499999999999999999999999999999&lt;/P&gt;
  &lt;P&gt;write: lv_decfloat34_4.&lt;BR /&gt; &lt;BR /&gt; data lv_f_1 type f.&lt;BR /&gt; data lv_f_2 type f.&lt;BR /&gt; data lv_f_3 type f.&lt;BR /&gt; data lv_f_4 type f.&lt;BR /&gt; &lt;BR /&gt; lv_f_1 = '154.8'.&lt;BR /&gt; lv_f_2 = 37.&lt;BR /&gt; lv_f_3 = 144.&lt;BR /&gt; &lt;BR /&gt; lv_f_4 = lv_f_2 / lv_f_3.&lt;BR /&gt; lv_f_4 = lv_f_4 * lv_f_1.&lt;/P&gt;
  &lt;P&gt;* result is 3,9774999999999999E+01&lt;/P&gt;
  &lt;P&gt;write: lv_f_4.&lt;BR /&gt; &lt;BR /&gt; data lv_p_1(16) type p DECIMALS 14.&lt;BR /&gt; data lv_p_2(16) type p DECIMALS 14.&lt;BR /&gt; data lv_p_3(16) type p DECIMALS 14.&lt;BR /&gt; data lv_p_4(16) type p DECIMALS 14.&lt;BR /&gt; &lt;BR /&gt; lv_p_1 = '154.8'.&lt;BR /&gt; lv_p_2 = 37.&lt;BR /&gt; lv_p_3 = 144.&lt;BR /&gt; &lt;BR /&gt; lv_p_4 = lv_p_2 / lv_p_3.&lt;BR /&gt; lv_p_4 = lv_p_4 * lv_p_1.&lt;/P&gt;
  &lt;P&gt;* result is 39,77499999999931&lt;/P&gt;
  &lt;P&gt;write: lv_p_4.&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;I've also made a similar experiment with C++. The result is the same as JAVA. &lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;As customer is verifying result with Excel, which gives 39.775, not equal to our result. So we meet the problem. Can anybody help with this issue? &lt;/P&gt;
  &lt;P&gt;Thanks,&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Aicro&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 02:59:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/a-calculation-precision-issue-with-abap/m-p/634218#M26732</guid>
      <dc:creator>aicro_ai</dc:creator>
      <dc:date>2018-04-18T02:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: A calculation precision issue with ABAP.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/a-calculation-precision-issue-with-abap/m-p/634219#M26733</link>
      <description>&lt;P&gt;As per SAP predefined data elements, Decfloat16 can have 16 decimals and decfloat34 can have 34 decimals. &lt;/P&gt;
  &lt;P&gt;You can do the wrapper type P with 3 decimal to convert into desired decimal format. &lt;/P&gt;
  &lt;P&gt;below is code snippet you may use. &lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;DATA lv_decfloat34_1 TYPE f.
DATA lv_decfloat34_2 TYPE f.
DATA lv_decfloat34_3 TYPE f.
DATA lv_decfloat34_4 TYPE f.
DATA lv_decfloat34_5 TYPE p DECIMALS 3.


lv_decfloat34_1 = '154.8'.lv_decfloat34_2 = 37.lv_decfloat34_3 = 144.
lv_decfloat34_4 = lv_decfloat34_2 / lv_decfloat34_3.lv_decfloat34_4 = lv_decfloat34_1 * lv_decfloat34_4.
lv_decfloat34_5 = lv_decfloat34_4

WRITE: lv_decfloat34_5.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Apr 2018 04:15:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/a-calculation-precision-issue-with-abap/m-p/634219#M26733</guid>
      <dc:creator>former_member564522</dc:creator>
      <dc:date>2018-04-18T04:15:39Z</dc:date>
    </item>
    <item>
      <title>Re: A calculation precision issue with ABAP.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/a-calculation-precision-issue-with-abap/m-p/634220#M26734</link>
      <description>&lt;P&gt;&lt;/P&gt;
  &lt;P&gt;If you read the ABAP documentation, you'll understand the reason (with 14 digits after the decimal point, 37/144 is stored as an unprecise value of 0.25694444444444, it can't store the fact that there's an endless sequence of "4", so because of the missing "4" from the 15th position, if you multiply by 37 you get 39.77499999999931).&lt;/P&gt;
  &lt;P&gt;But as I'm not expert with C++/java, I can't explain how these languages can get the right result because I thought that the "double" storage was the same logic as for ABAP type "F" (binary floating point on 8 bytes, with same mantissa and so on). Of course, here you are testing the decimal floating point types, which are different from "double".&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 04:45:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/a-calculation-precision-issue-with-abap/m-p/634220#M26734</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2018-04-18T04:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: A calculation precision issue with ABAP.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/a-calculation-precision-issue-with-abap/m-p/634221#M26735</link>
      <description>&lt;P&gt;Hi Himanshu,&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Thanks for your reply, but I do not want such conversion, as it's impossible to see to which decimal shall I reserve, ie in this case I have 3 decimal, but in other cases we need more. What JAVA and C++ does is so nature that it directly tells me the "right" result. &lt;/P&gt;
  &lt;P&gt;So I'm wondering, is there any way, including function modules, can have the same behavior like that of JAVA and C++. &lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 05:11:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/a-calculation-precision-issue-with-abap/m-p/634221#M26735</guid>
      <dc:creator>aicro_ai</dc:creator>
      <dc:date>2018-04-18T05:11:48Z</dc:date>
    </item>
    <item>
      <title>Re: A calculation precision issue with ABAP.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/a-calculation-precision-issue-with-abap/m-p/634222#M26736</link>
      <description>&lt;P&gt;Please read SAP's documentation about &lt;A href="https://help.sap.com/http.svc/rc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abenarith_type.htm"&gt;calculation type &lt;/A&gt;and &lt;A href="https://help.sap.com/http.svc/rc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abenconversion_elementary.htm"&gt;conversion rules&lt;/A&gt;.&lt;/P&gt;
  &lt;P&gt;Please read SAP's documentation about &lt;A href="https://help.sap.com/http.svc/rc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abendec_floating_point_functions.htm"&gt;ROUND&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 05:53:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/a-calculation-precision-issue-with-abap/m-p/634222#M26736</guid>
      <dc:creator>retired_member</dc:creator>
      <dc:date>2018-04-18T05:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: A calculation precision issue with ABAP.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/a-calculation-precision-issue-with-abap/m-p/634223#M26737</link>
      <description>&lt;P&gt;The output of your calculation is 39+(31/40) so is, exactly, 39.775. &lt;/P&gt;
  &lt;P&gt;What happens if you do it in a single step?&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;lv_decfloat34_4 = lv_decfloat34_1 * lv_decfloat34_2 / lv_decfloat34_3.&amp;lt;br&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Apr 2018 06:09:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/a-calculation-precision-issue-with-abap/m-p/634223#M26737</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2018-04-18T06:09:18Z</dc:date>
    </item>
  </channel>
</rss>

