Topic: Error Rounding with Tax

I want to make a Purchase order with IDR currency
My purchase is use 10% tax with unit price of IDR 17,586,500.00, so I input should be IDR 15,987,727.27. (Attach PO1).
But if the quantity change to 2 units, amount total result IDR 35,172,999.99 (attach PO2). It should be rounding to IDR 35,173,000.00.

Please help solution for this problem?

FrontAccounting ver 2.4.2

PO1.png
PO2.png

Re: Error Rounding with Tax

https://stackoverflow.com/questions/4921466/php-rounding-error

Try on a 64 bit machine.
Provide details of PHP version number and Apache/mySQL/OS versions.

Re: Error Rounding with Tax

Hi,

sorry for late reply, current vps server is using:
httpd-2.4.6-45.el7.centos.4.x86_64
mariadb-5.5.52-1.el7.x86_64
on centos 7, this problem is that will very likely to happen, as vendor do include tax in their price, sometimes don't
so the calc will cause floating point decimal.

pls advice. already tested in the latest FA 2.4.2

thanks

Re: Error Rounding with Tax

Increase the number of decimal places for Exchange Rate to 8 from the default 4 in Setup -> Display Setup (Preferences).

Re: Error Rounding with Tax

thanks for the feedback,
we still try first to check this will rounding to expected values.

thanks

Re: Error Rounding with Tax

I have change the decimal places.
The results below:
4 decimal with 1 qty.png
4 decimal with 2 qty.png
8 decimal with 2 qty.png
8 decimal with 2 qty.png

Any other solution?

Post's attachments

VariousPOErrors.zip 32.6 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.

Re: Error Rounding with Tax

Try to see if the latest debian based php version solves your issue.
Check out MariaDB as well.

The easiest way is for you to use the companys' default base home currency as IDR and work from there using standard 8 decimal places for exchange rates and 2 decimals for prices/amounts.

You can play around with the constant FLOAT_COMP_DELTA defined in current_user.inc which is by default set at 0.004. Checkout the function round2() and number_format2() on the use of the value +/- .0000000001 in the same file.

Also see if you can use a larger unit for items to get meaningful rates per unit.

Try 8 decimal places for Exchange Rates and 0 or 2 decimal places for Prices/Amounts.

Re: Error Rounding with Tax

I've tried the way you suggest, but it still doesn't work.
Display Setup.png

Our Home Currency is IDR, and we only make transactions with IDR currency only. so we do not need any other currency exchange rates
I have explained in first post, if the quantity order 1 unit then Amount Total is correct, but  for quantity above 2 units make Amount Total wrong.

Post's attachments

Display Setup.png 20 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.

Re: Error Rounding with Tax

Try smaller numbers first and see when the error occurs. You should not exhaust the floating point precision of your variable.

This is a PHP issue:

$a = 31975454.54545400;
$b = 3197545.45454540;

echo $a+$b;

// Outputs: 35172999.999999

What is the value of precision in your php.ini file?
Increase it and see what happens.

Increasing it from 14 to 17 in PHP 5.3.3 on 32 bit XAMPP:

$a = 31975454.54545400;
$b = 3197545.45454540;

echo $a+$b;

// Outputs 35172999.999999397

This might do the job.

In the code, it can be dynamically set as well:

ini_set('precision', 17);