I am trying to display all prices with 4 decimals (i know a little bit weird but the customer demanded this). I have overwritten Mage/Core/Store, changed the currency.php precision in the Zend lib and adjusted Mage_Directory_Model_Currency.

In the backend, all my prices are displayed correctly but in the frontend i receive a price rounded to 2 decimals followed by 00. Especially the tier price is very crucial.

Since i dont have any knowledge in pricing i have tried some tutorials on Magento Forum with no success. I also tried 2 extensions with no luck.

Any help?

  • 1
    4 decimal precision is inherently imprecise in Magento.
    – benmarks
    Feb 25, 2013 at 23:34
  • What prices are stored in database after editing prices in backend? Maybe problem is not in frontend? Feb 26, 2013 at 6:49
  • @benmarks please put this as an answer, you are completely right, I have tested it thoroughly and I'm getting 1 problem after another Feb 26, 2013 at 9:45
  • I'll defer to someone with the time to really get into the specifics - afraid I'm short of time right now. Perhaps you could post this yourself along with your findings. The issue is a mix of how PHP deals with float precision and how the framework handles rounding for precision.
    – benmarks
    Feb 26, 2013 at 19:54
  • Yes, will try to find some time @benmarks Feb 26, 2013 at 21:34

3 Answers 3


I think you'll find what you need in the format method inside app/code/core/Mage/Directory/Model/Currency.php.

 * Format price to currency format
 * @param   double $price
 * @param   bool $includeContainer
 * @return  string
public function format($price, $options=array(), $includeContainer = true, $addBrackets = false)
    return $this->formatPrecision($price, 2, $options, $includeContainer, $addBrackets);
  • tried that didn't work :( Feb 25, 2013 at 21:37
  • You set the precision from 2 to 4? I tested this on a stock install and it changed my price displays right away. You may want to check for other modules that are overwriting this class.
    – pspahn
    Feb 25, 2013 at 22:18
  • been looking for classes that extend app/code/core/Mage/Directory/Model/Currency.php in my local and community folder with no luck, didn't find some kind of observer either pretty weird :( Feb 25, 2013 at 22:29
  • 1
    Also check the design/frontend/[package]/[theme]/catalog/product/price.phtml template to make sure it is still using the core currency helper.
    – pspahn
    Feb 25, 2013 at 23:43
  • @pspahn Can you please let me know how I can add a check in this function so i can display a precission on 4 digits ONLY on products that have tier pricing and not on every product? I tried by if (Mage::registry('product')->getTierPrice()) which works on product page but I can't get something that works on category page loop. Mage::registry('current_product') don't. Aug 24, 2017 at 8:40

I had to completely rewrite my template's price.phtml anyway, and I used
<?php printf("$%.2f", $_finalPrice) ?> so you could do the same but with %.4f

Also, if needing to perform comparisons on floats, I recommend:
if( abs($_price1 - $_price2) < .0001 ) instead of if($_price1 == $_price2)

Sometimes, php's type flexibility induces unexpected errors, so explicit casting to your desired data type is often needed: $margin=(float)1-$margin; I have gotten to where I don't even try to stack multiple math operations into one line of code.


I decided not to do it and adviced the customer to refrain from pushing it because I could not get any exact results. As mentioned in the comments:

4 decimal precision is inherently imprecise in Magento.

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.