2

I have created a block of code that will show a row of products if the user doesn't hit the free delivery limit. My only problem is the way the price is being displayed. it shows it like £34.9900 instead of just £39.99 like it does on every other page.

This is my line of code that shows the price

<p class="upsell_pro_price"><?php echo $_product->getPrice();?></a></p>

If you know why this is doing this and can help would be much appreciated.

Thank you

2 Answers 2

5

You should use the Magento Price format helper which formats the price according to the store configuration:

Mage::helper('core')->formatPrice($_product->getPrice());
0
5

You can use PHP to format your price. you can use the code like

number_format($_product->getPrice(), 2, '.', '')

It will display price upto 2 digits.

[Edit]

I think using Magento Format price functionality will be better option. I answered it in a hurry over viewing the top level problem of number formatting.

You should use instead

Mage::helper('core')->formatPrice($_product->getPrice());

4
  • thank you, when it will let me i will accept your answer, thanks again
    – Adam Allen
    Aug 8, 2014 at 11:49
  • @Dexter you should really utilise the built in Magento functionality in the form of formatPrice()
    – Dave
    Aug 8, 2014 at 11:51
  • @Dave: Yes you are right Mage::helper('core')->formatPrice($_product->getPrice()); too is a better option
    – Dexter
    Aug 8, 2014 at 11:52
  • ok cheers, i have changed it now :)
    – Adam Allen
    Aug 8, 2014 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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