Format Price in Magento 1.9

Format Price in Magento 1.9

October 11, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Format Price in Magento 1.9

Formatting Prices in Magento 1.9: A Comprehensive Guide

In Magento 1.9, displaying prices effectively is crucial for enhancing user experience and driving conversions. The core price formatting function provided by Magento allows for basic currency conversion but lacks flexibility for advanced styling needs like separating the integer part of the price from the decimal part.

Understanding the Default Price Formatting Code

The default pricing code snippet you shared is as follows:

<?php echo $_coreHelper->currency($_finalPriceInclTax, true, false) ?>

This code uses Magento’s core helper Mage_Core_Helper_Data to convert the price into a formatted currency string. The parameters passed are:

  • $_finalPriceInclTax: The final price including tax
  • true: Whether to use the store currency symbol or not
  • false: A flag indicating whether to apply rounding rules

The output of this code is a fully formatted price, e.g., 199,00€. While functional, it doesn’t provide options for separating the integer and decimal parts.

The Challenge: Separating Integer and Decimal Parts

Your requirement is to display the integer part of the price (the number before the comma) in one style and the remainder in another. To achieve this, we’ll need to manually break down the formatted price into its components.

A Custom Solution for Price Formatting

To tackle this issue, you can create a custom pricing helper that breaks down the formatted price string. Here’s a sample solution using a separate class named Custom_Price_Helper:

  1. Create a new file at app/code/local/Custom/Price/Helper/Data.php and add the following code:
class Custom_Price_Helper extends Mage_Core_Helper_Abstract
{
    public function formatPrice($price, $includeContainer = true)
    {
        $formattedPrice = Mage::helper('core')->currency($price, true, false);

        if ($includeContainer) {
            return '<div class="price-integer">' . substr($formattedPrice, 0, strpos($formattedPrice, ',') + 1) . '</div>' .
                   '<span class="price-decimal">' . substr($formattedPrice, strpos($formattedPrice, ',') + 2) . '</span>';
        } else {
            return $formattedPrice;
        }
    }
}

This helper extends the core Mage_Core_Helper_Abstract and provides a custom method formatPrice. It uses Magento’s core currency helper to format the price and then manually separates the integer part from the decimal part using PHP’s substr function.

  1. Include the new pricing helper in your template file (price.phtml) as follows:
<?php echo $this->helper('custom_price')->formatPrice($_finalPriceInclTax, true) ?>

Styling the Integer and Decimal Parts

To apply different styles to the integer and decimal parts of the price, you can use CSS. Add the following styles to your theme’s css folder:

.price-integer {
    font-size: 18px;
    font-weight: bold;
}

.price-decimal {
    font-size: 14px;
}

Conclusion

While Magento provides a basic currency formatting helper, more advanced pricing styles often require custom solutions. By creating a separate price formatting class, you can achieve the desired separation of integer and decimal parts while maintaining consistency with Magento’s core functionality.

This approach allows for greater flexibility in styling prices throughout your store, enhancing the visual appeal and user experience. For more information on customizing Magento themes and templates, check out our blog post Mastering Magento 1.x Theme Development at Laravel Company.

Remember to always test changes thoroughly in a development environment before deploying them to your live store. Happy coding!

Magento 1 Pricing Errors

Our network