Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9187235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:43:08+00:00 2026-06-17T19:43:08+00:00

In Magento, I want to apply a custom PHP function to the display of

  • 0

In Magento, I want to apply a custom PHP function to the display of prices on the frontend without changing the actual numerical price on the backend / shopping cart.

To be specific, I want to remove decimals on the display price when there are no cents in the price. For example, $19.00 would display as $19 but $19.99 would display as $19.99.

I found a PHP function on PHP.net that will perform this change for me:

// 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 == 2 ? '0.00' : '0'); // output zero
        } else { // value
          if (floor($number) == $number) { // whole number
            $money = number_format($number, ($cents == 2 ? 2 : 0)); // format
          } else { // cents
            $money = number_format(round($number, 2), ($cents == 0 ? 0 : 2)); // format
          } // integer or decimal
        } // value
        return $money;
      } // numeric
    } // formatMoney

I do not want to have to change Magento templates to apply this function, because the prices appear all over the place. It would be a nightmare to update all the templates.

I would like to know whether there is a place I can use this function to format the display of the price globally so it affects the display of all prices everywhere from one spot.

Already I have spent a few hours poking around various Magento files, including:

app/code/core/Mage/Directory/Model/Currency.php

public function format <– This function changes the real price, not the display of the price.

app/code/core/Mage/Catalog/Model/Product.php:

public function getFormatedPrice <– This function looked promising but didn’t do anything for me.

I also looked at these files without anything jumping out as an obvious place:

app/code/core/Mage/Catalog/Block/Product.php

app/code/core/Mage/Catalog/Block/Product/Price.php

app/code/core/Mage/Catalog/Block/Product/View.php

Do you think it’s possible to find one place in Magento that I can hack to apply my custom PHP function to the display of the price (and not the actual numerical price in the shopping cart)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:43:09+00:00Added an answer on June 17, 2026 at 7:43 pm

    I’m not sure that catalog_product_get_final_price will work as you want, so another solution that i propose is to override formatTxt from Mage_Directory_Model_Currency

    In that function you can check if price has decimals or not and set option $options['precision']=0; if you want that price to not have decimals (like xx.00).

    Eg:

    public function formatTxt($price, $options=array())
    {
      if(is_numeric( $price ) && floor( $price ) == $price){
         $options['precision']=0;
      }
      return parent::formatTxt($price, $options);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to include external PHP script in Magento CMS Pages e.g. **http://myhost/magento/custom/script.php** <?php
I want to translate a frontend Magento store using only one csv file. So
magento How do I? manual order (backend) free shipping, actually pickup Hi we want
Magento site is not updating the price according to the custom option added. I
I want to display google checkout at one page checkout page in magento, so
I have a custom magento sales module. I want to translate the custom mail
I'm building a Magento store and want to be able to display a list
I want to test a Magento block function. I don't know, how to call
I want to display the product options value in a Magento Product Page. I
I want to customize my default search in magento website. In frontend, If customer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.