magento - PHP rounding issue

425

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

People are also looking for solutions to the problem: html - php Captcha is returning the old value and checks the old value

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.