<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Wrong Decimal Calculations</title><link>https://community.appian.com/discussions/f/user-interface/11300/wrong-decimal-calculations</link><description>In one of the applications, I observed the some unexpected behavior/results from Appian (possible bug) for basic +/- calculations on decimals. 
 
 92000 - (7000.27 + 73000.27 + 2000.33 + 9999.13) =&amp;gt; -1.455192e-011 [expected result is &amp;quot;0&amp;quot;] 
 &amp;lt;Please evaluate</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Wrong Decimal Calculations</title><link>https://community.appian.com/thread/49703?ContentTypeID=1</link><pubDate>Thu, 26 Oct 2017 18:41:08 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:73f107b2-fecd-4b17-9f5e-449750901002</guid><dc:creator>Puspendu Pal</dc:creator><description>Agreed with James,&lt;br /&gt;
&lt;br /&gt;
In our project, we used combination of fixed() and round()  functions to over come this issue.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wrong Decimal Calculations</title><link>https://community.appian.com/thread/49699?ContentTypeID=1</link><pubDate>Thu, 26 Oct 2017 13:04:24 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:31f8dee1-1e27-41aa-8659-24017c8ef3fb</guid><dc:creator>James</dc:creator><description>&lt;p&gt;Hi @Vaibhav,&lt;/p&gt;
&lt;p&gt;This looks likely to be a rounding error due to Floating Point Arithmetic. &amp;nbsp;I believe Appian uses the Java Primitive double for Number(decimal) under the hood, which is a 64-bit IEEE 754 floating point. &amp;nbsp;IEEE 754 is the technical standard for floating-point computation, this is the most widely used standard for floating point arithmetic and number formats.&lt;/p&gt;
&lt;p&gt;The issue is that some numbers have an infinite number of digits, and can not be represented with 100% precision with only 64-bits. &amp;nbsp;But it&amp;#39;s not just Pi that can be affected by this, something as simple as 1/10, or 0.1 can be affected.&lt;/p&gt;
&lt;p&gt;For instance, the below code would print false to the console in Java:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;double x1 = 0.3; &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;double x2 = 0.1 + 0.1 + 0.1; &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;StdOut.println(x1 == x2);&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;However, the below code would print true:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;double z1 = 0.5; &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;double z2 = 0.1 + 0.1 + 0.1 + 0.1 + 0.1; &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;StdOut.println(z1 == z2);&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This is just a limitation of the IEEE 754 standard, and there&amp;#39;s few ways to get around it.&amp;nbsp; To do so purely in Appian will require some rouding work around, or similiar, as suggest by @manikandanp13&lt;/p&gt;
&lt;p&gt;Financial Java applications often use the BigDecimal Class, which&amp;nbsp;provides more precision through larger storage of numbers and more robust mathematical functions.&amp;nbsp; You could consider building a plugin that would allow access to the BigDecimal Class and it&amp;#39;s functionality.&amp;nbsp; I did a quick search on shared components and found&amp;nbsp;&lt;a href="https://forum.appian.com/suite/tempo/records/item/lMBCLGOdlMUpdGVqW3dQaIKmclBmvvNEj8vu_cjb7T-5YiPr4Fu8ly5Yj1s09uenE4RYzA8zKyx7eiUhe2kLnO1l8v4PFM9U_yr4yMcNagKDuviUQ/view/summary"&gt;https://forum.appian.com/suite/tempo/records/item/lMBCLGOdlMUpdGVqW3dQaIKmclBmvvNEj8vu_cjb7T-5YiPr4Fu8ly5Yj1s09uenE4RYzA8zKyx7eiUhe2kLnO1l8v4PFM9U_yr4yMcNagKDuviUQ/view/summary&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Some additional reading that goes more into the Rounding issue of Floating Point Arithmetic:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html"&gt;https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://introcs.cs.princeton.edu/java/91float/"&gt;https://introcs.cs.princeton.edu/java/91float/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best Regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wrong Decimal Calculations</title><link>https://community.appian.com/thread/49690?ContentTypeID=1</link><pubDate>Thu, 26 Oct 2017 02:15:13 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:bcfa265f-d534-4422-932f-10a9022e816e</guid><dc:creator>manikandanp13</dc:creator><description>absolutely; This calculation produce 92000 - (7000.27 + 73000.27 + 2000.33 + 9999.13) =&amp;gt; -1.455192e-011 i.e. - 0.00000000001455192&lt;br /&gt;
Please refer results when use round function.&lt;br /&gt;
= round ((92000 - (7000.27 + 73000.27 + 2000.33 + 9999.13)),0) =&amp;gt; -0&lt;br /&gt;
= round ((92000 - (7000.27 + 73000.27 + 2000.33 + 9999.13)),20) =&amp;gt; -1.455192e-011&lt;br /&gt;
= round ((92000 - (7000.27 + 73000.27 + 2000.33 + 9999.12)),0) =&amp;gt; 0&lt;br /&gt;
= round ((92000 - (7000.27 + 73000.27 + 2000.33 + 9999.12)),20) =&amp;gt; 0.01&lt;br /&gt;
&lt;br /&gt;
not sure have use some mathematical functions as best practices when do mathematical operations&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wrong Decimal Calculations</title><link>https://community.appian.com/thread/49689?ContentTypeID=1</link><pubDate>Wed, 25 Oct 2017 22:22:34 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:6223c52e-51b3-4961-8934-46912dd861ee</guid><dc:creator>aloks0189</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;a href="/members/vaibhavt308"&gt;Vaibhav Tandale&lt;/a&gt;&amp;nbsp;It&amp;#39;s really weird, i believe it&amp;#39;s better you raise a support ticket to Product Team, because it&amp;#39;s normal calculation and it should work.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>