magento - PHP rounding issue
We have a problem on our Google Shopping feed which seems to be a rounding issue. THis has caused Google to suspend our feed and the combined might of myself and 2 development agencies we use can not seem to fix it.
The script does the following;
Get the price (or special price if on special) of the product;
if ($product->getSpecialPrice() &&
($product->getSpecialPrice() < $product->getPrice()))
{
$tempPrice = $product->getSpecialPrice();
}
else
{
$tempPrice = $product->getPrice();
}
Add the VAT by multiplying by 1.2
$_priceIncludingTax = $tempPrice * 1.2;
Using the PHP round() function to round the price to the nearest 2 decimal places (this should do half up and less down by default, i.e 1.5 = 2 and 1.4 = 1 (according to the PHP documentation))
$_priceIncludingTax = round($_priceIncludingTax, 2);
This should work for all our products for example the 3 examples below;
SKU | Price in website backend | X 1.2 | rounded | Whats actually in feed
DL229 | 589.86 | 707.832 | 707.83 | 707.84
SKU | Price in website backend | X 1.2 | rounded | Whats actually in feed
CB020 | 9.06 | 10.872 | 10.87 | 10.88
SKU | Price in website backend | X 1.2 | rounded | Whats actually in feed
DM056 | 16.93 | 20.316 | 20.32 | 20.31