<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[FrontAccounting forum — rounded errors]]></title>
		<link>https://frontaccounting.com/punbb/viewtopic.php?id=2681</link>
		<atom:link href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=2681&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in rounded errors.]]></description>
		<lastBuildDate>Wed, 04 Jan 2012 12:59:01 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: rounded errors]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=11441#p11441</link>
			<description><![CDATA[<p>I have to change (a while ago) the SQL&nbsp; (not the PHP) in the themes/execlusive/render.php.<br />That&#039;s everything I found so fa</p><p>/Elax</p>]]></description>
			<author><![CDATA[null@example.com (elax)]]></author>
			<pubDate>Wed, 04 Jan 2012 12:59:01 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=11441#p11441</guid>
		</item>
		<item>
			<title><![CDATA[Re: rounded errors]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=11440#p11440</link>
			<description><![CDATA[<p>ok, elax, please continue report files and lines that need the new floatcmp filter.</p><p>The following files have been updated in the HG repository:<br />/reporting/rep101.php<br />/reporting/rep102.php<br />/reporting/rep201.php<br />/reporting/rep202.php<br />/sales/inquiry/customer_inquiry.php</p><p>Other files will be added as we find more.</p><p>The theme exclusive has been updated for this about a month ago. Please re-install.</p><p>/Joe</p>]]></description>
			<author><![CDATA[null@example.com (joe)]]></author>
			<pubDate>Wed, 04 Jan 2012 12:53:32 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=11440#p11440</guid>
		</item>
		<item>
			<title><![CDATA[Re: rounded errors]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=11439#p11439</link>
			<description><![CDATA[<div class="quotebox"><cite>joe wrote:</cite><blockquote><p>and see if it is ok with the floatcmp.<br />reporting/rep102.php had alreade a filter in the sql used in the file.</p><p>/Joe</p></blockquote></div><p>This report should be modified too. Even it&#039;s filtered by mysql (and I think mysql have the same problem).<br />array_sum, sum float in php so it has potentialy the problem (Anyway any comparaison of a floating number to 0 as this problem)</p><p>That works with floatcmp.</p><p>/Elax</p>]]></description>
			<author><![CDATA[null@example.com (elax)]]></author>
			<pubDate>Wed, 04 Jan 2012 11:45:16 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=11439#p11439</guid>
		</item>
		<item>
			<title><![CDATA[Re: rounded errors]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=11437#p11437</link>
			<description><![CDATA[<p>elax, please add the following lines in /includes/current_user.inc after the function number_format2</p><div class="codebox"><pre><code>/* price/float comparision helper to be used in any suspicious place for zero values? 
usage:
if (!floatcmp($value1, $value2)) 
    compare value is 0
*/

define(&#039;FLOAT_COMP_DELTA&#039;, 0.0000001);

function floatcmp($a, $b)
{
    return $a - $b &gt; FLOAT_COMP_DELTA ? 1 : $b - $a &gt; FLOAT_COMP_DELTA ? -1 : 0;
}</code></pre></div><p>and see if it is ok with the floatcmp.<br />reporting/rep102.php had alreade a filter in the sql used in the file.</p><p>/Joe</p>]]></description>
			<author><![CDATA[null@example.com (joe)]]></author>
			<pubDate>Wed, 04 Jan 2012 11:06:27 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=11437#p11437</guid>
		</item>
		<item>
			<title><![CDATA[Re: rounded errors]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=11431#p11431</link>
			<description><![CDATA[<p>Just search for &#039;== 0&#039; in the code.<br />So far I found it in 3 files </p><p>sales/inquiry/customer_inquiry.php<br />reporting/rep101.php<br />reporting/rep102.php</p><p>And in the exclusive theme<br />themes/exclusive/renderer.php</p><p>Thanks<br />/Elax</p>]]></description>
			<author><![CDATA[null@example.com (elax)]]></author>
			<pubDate>Wed, 04 Jan 2012 09:40:25 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=11431#p11431</guid>
		</item>
		<item>
			<title><![CDATA[Re: rounded errors]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=11430#p11430</link>
			<description><![CDATA[<p>Yes, Elax, you are right . This is really real example <img src="https://frontaccounting.com/punbb/img/smilies/smile.png" width="15" height="15" alt="smile" />. Surely any reported issue of this kind will be fixed.<br />Janusz</p>]]></description>
			<author><![CDATA[null@example.com (itronics)]]></author>
			<pubDate>Wed, 04 Jan 2012 09:35:35 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=11430#p11430</guid>
		</item>
		<item>
			<title><![CDATA[Re: rounded errors]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=11426#p11426</link>
			<description><![CDATA[<p>Thanks elan,</p><p>If you have a detailed list of these happenings, I will gladly change the filter.</p><p>/Joe</p>]]></description>
			<author><![CDATA[null@example.com (joe)]]></author>
			<pubDate>Wed, 04 Jan 2012 08:11:37 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=11426#p11426</guid>
		</item>
		<item>
			<title><![CDATA[Re: rounded errors]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=11423#p11423</link>
			<description><![CDATA[<div class="quotebox"><cite>itronics wrote:</cite><blockquote><p>Of course I can be wrong, so we can switch with all the database double columns to&nbsp; numeric, as soon&nbsp; as the problem&nbsp; will be proven&nbsp; on real example <img src="https://frontaccounting.com/punbb/img/smilies/wink.png" width="15" height="15" alt="wink" />.<br />Janusz</p></blockquote></div><p>I have an real example , and strangely it&#039;s a php problem<br />&lt;?php<br />&nbsp; &nbsp;echo (335.74+30.52) == (305.22+61.04) ? &quot;equal&quot; : &quot;not equal&quot;;<br />?&gt;</p><p>&gt;&gt; not equal.</p><p>If you do the same in SQL it&#039;s equal (I don&#039;t know why).<br />Anyway I have this real , you can do it yourself on a test database </p><p>The invoice is 305.22 + 61.04 of VAT <br />And I payed with 2 different payments : one of 335.74 and the second one of 30.52&nbsp; (a credit note)</p><p>This payment appears in the list of overdue invoices but not in red. I think the &quot;filtering&quot; is done on the &#039;sales/inquiry/customer_inquiry.php&#039; line 212. <br />If you change <br />&nbsp; &nbsp;(abs($row[&quot;TotalAmount&quot;]) - $row[&quot;Allocated&quot;] != 0)<br />by<br />&nbsp; &nbsp;(abs(abs($row[&quot;TotalAmount&quot;]) - $row[&quot;Allocated&quot;]) &gt; 1e-6)</p><p>everything is fine.</p><p>(Even if the column was decimal we will still have the problem as the numbers will be added in PHP)</p><p>/Elax</p>]]></description>
			<author><![CDATA[null@example.com (elax)]]></author>
			<pubDate>Wed, 04 Jan 2012 00:10:39 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=11423#p11423</guid>
		</item>
		<item>
			<title><![CDATA[Re: rounded errors]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=11422#p11422</link>
			<description><![CDATA[<div class="quotebox"><blockquote><p>Of course I can be wrong, so we can switch with all the database double columns to&nbsp; numeric, as soon&nbsp; as the problem&nbsp; will be proven&nbsp; on real example <img src="https://frontaccounting.com/punbb/img/smilies/wink.png" width="15" height="15" alt="wink" />.Janusz</p></blockquote></div><p>I have an real example , and strangely it&#039;s a php problem&lt;?php&nbsp; &nbsp;echo (335.74+30.52) == (305.22+61.04) ?</p>]]></description>
			<author><![CDATA[null@example.com (elax)]]></author>
			<pubDate>Wed, 04 Jan 2012 00:08:25 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=11422#p11422</guid>
		</item>
		<item>
			<title><![CDATA[Re: rounded errors]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=11419#p11419</link>
			<description><![CDATA[<p>It is not the double precission that causes this problem. Consider the following:</p><p>When you pay and allocate customers/suppliers in another currency than the customer/supplier there would occasionally be a small leftover, either positive or negative in the AR/AP ledger. FA does not consider the record as fully paid. That is the reason for doing the check for either 0.0001 or 1e-6 to check that the record is &#039;paid&#039;.</p><p>So I guess we can can continue with double precission.</p><p>/Joe</p>]]></description>
			<author><![CDATA[null@example.com (joe)]]></author>
			<pubDate>Tue, 03 Jan 2012 23:00:03 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=11419#p11419</guid>
		</item>
		<item>
			<title><![CDATA[Re: rounded errors]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=11415#p11415</link>
			<description><![CDATA[<p>Yes, I know this legendary rounding problem, but I couldn&#039;t find single place in FA where addition is done so many times without rounding, that the error has a chance to rise above half a cent. Of course I can be wrong, so we can switch with all the database double columns to&nbsp; numeric, as soon&nbsp; as the problem&nbsp; will be proven&nbsp; on real example <img src="https://frontaccounting.com/punbb/img/smilies/wink.png" width="15" height="15" alt="wink" />.<br />Janusz</p>]]></description>
			<author><![CDATA[null@example.com (itronics)]]></author>
			<pubDate>Tue, 03 Jan 2012 19:59:17 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=11415#p11415</guid>
		</item>
		<item>
			<title><![CDATA[Re: rounded errors]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=11368#p11368</link>
			<description><![CDATA[<p>There are some situations, f.i. when you get payments from your customers or pay your suppliers in another currency than the customers/suppliers currency, that you may be left with a small rounding error. This is only located in the receivals / payment ledgers.<br />This is the reason for using this small rounding fix.</p><p>/Joe</p>]]></description>
			<author><![CDATA[null@example.com (joe)]]></author>
			<pubDate>Wed, 28 Dec 2011 21:40:09 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=11368#p11368</guid>
		</item>
		<item>
			<title><![CDATA[Re: rounded errors]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=11364#p11364</link>
			<description><![CDATA[<p>I agree 100 % with you. However the source of the problem is to store number as float (or double) in the database rather than using decimal type. <br />You should know that floating number can&#039;t represent exactly every decimal numbers (0.1 for example is 1/10 and needs an infinite number of digit in base-2) and you can&#039;t just compare floating number to 0 <br />The problem appears mostly when you use discount or pay an invoice in many payment, therefore to know if the invoice has been fully paid or not, you just not compare the two amounts but have to compare one amount with the sum of other (the amount paid vs the invoice amount + the discount).</p><p>/Elax</p>]]></description>
			<author><![CDATA[null@example.com (elax)]]></author>
			<pubDate>Wed, 28 Dec 2011 11:57:29 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=11364#p11364</guid>
		</item>
		<item>
			<title><![CDATA[Re: rounded errors]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=11360#p11360</link>
			<description><![CDATA[<p>Well, I&#039;m not sure where the problem appears, but in general case rounding errors should never appear in accounting application. This simply can break balances in some places. Please report where you have found the problem, maybe better approach is just to avoid the problem at the source?</p><p>Janusz</p>]]></description>
			<author><![CDATA[null@example.com (janusz)]]></author>
			<pubDate>Wed, 28 Dec 2011 10:54:25 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=11360#p11360</guid>
		</item>
		<item>
			<title><![CDATA[Re: rounded errors]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=11264#p11264</link>
			<description><![CDATA[<p>Well I guess the rounding problems is solved by using something like 0.0001 (it has been used in /gl/gl_journal.php.<br />Or as you suggest 1e-6 is also a good approach. You decide.</p><p>I guess you can find my email by pressing my username joe in the left column. You can send the files here.</p><p>/Joe</p>]]></description>
			<author><![CDATA[null@example.com (joe)]]></author>
			<pubDate>Fri, 16 Dec 2011 21:55:25 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=11264#p11264</guid>
		</item>
	</channel>
</rss>
