I'm using this code for structured data.

<meta itemprop="price" content="<?php echo $_product->getPrice(); ?>">

I get the price that I need but it adds ".0000" at the end.

Please advise on how to remove those ".0000" or may be use a different code to call the price field.

  • Are you on Magento 1 Or 2 ? – Pawan Apr 2 at 3:54

If you want to remove all zeros you can use:

<meta itemprop="price" content="<?php echo (float) $_product->getPrice(); ?>">

Above code will remove all zeros.

If you want to keep specific number of zeros, you can use:

<meta itemprop="price" content="<?php echo number_format($_product->getPrice(), 2); ?>"> 

Above code will keep only 2 zeros after decimal

Hope Above will help!

  • Good answer. +1 – Shoaib Munir Apr 2 at 4:17
  • It worked. I used the first code you recommended. I entered . 4 to take out period and 4 zeros. Thank you so much for your help. – AlexT Apr 2 at 18:28
  • Glad to know @AlexT :). You can accept and up vote answer too :) – Pawan Apr 3 at 1:43
  • No problem :) where? – AlexT Apr 3 at 3:50
  • you just need to tick right icon, left to answer :) – Pawan Apr 3 at 4:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.