Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Best place to apply price formatting function
 
haligonia
Sr. Member
 
Total Posts:  97
Joined:  2009-02-28
 

Where is the best place to apply a price formatting function globally to all prices in Magento?

(I only want it to affect display price output on frontend, not actual numbers in the backend or checkout. For example, I want to format any price such as $68.00 to just $68 but keep decimals in case there are prices such as $33.50. And it should only affect the output as displayed to the visitor.)

I found a function on PHP.net that allows me to do exactly what I want:

// formats money to a whole number or with 2 decimals; includes a dollar sign in front
        function formatMoney($number$cents 1// cents: 0=never, 1=if needed, 2=always
          
if (is_numeric($number)) // a number
            
if (!$number// zero
              
$money = ($cents == '0.00' '0'); // output zero
            
else // value
              
if (floor($number) == $number// whole number
                
$money number_format($number, ($cents == 0)); // format
              
else // cents
                
$money number_format(round($number2), ($cents == 2)); // format
              
// integer or decimal
            
// value
            
return $money;
          
// numeric
        
// formatMoney

But where should I put this function and how can I apply it to getPriceHtml? I don’t want to have to edit every instance of a price in every template, so it should be global.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top