0

I have a site where the currency has been set to 5 decimal places because they price small items individually, such as £0.00023

but some products are more, such as £1.45, but the price is being displayed to the user as £1.45000 - how can I strip the last 0's off but only to 2 decimal places - so if a price is £1.00, it still leaves at least 2 0's.

In the price.phtml, the following line displays price, but I need to somehow strip the 0's..

<?php echo $_coreHelper->formatPrice($_finalPrice, false) ?>
0

Taken from this answer

https://stackoverflow.com/questions/6730180/format-price-in-the-current-locale-and-currency

I always use the following to format price

$formattedPrice = Mage::helper('core')->currency($finalPrice, true, false);
  • Thanks bob but this still shows the price with 5 decimals, is there a way I can strip off all the trailing 0's except the 2 after the decimal point, so £0.50000 becomes £0.50 ?? – Mike Jan 8 '16 at 11:32
  • what is being stored to $_finalPrice, also are you doing this within price template file or outside of price template? – Bobadevv Jan 8 '16 at 11:37
  • the actual value of $_finalPrice is 0.5 and I'm doing this from within the price.phtml albeit in a custom theme so not amending any core templates – Mike Jan 8 '16 at 11:41
  • what about if you try $formattedPrice = Mage::helper('core')->currency($finalPrice, false, false); – Bobadevv Jan 8 '16 at 11:44
  • ah oh wait might of confused things, the line of code I pasted above is slightly wrong, its $_regularPrice not $_finalPrice If I use your query in message above, $_regularPrice still returns 0.5 – Mike Jan 8 '16 at 12:07

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.