How To Remove Decimal From Magento-1 Prices?

20,490

Solution 1

In order to change price precision in magento you would need to overwrite some core files.

In the example below we are changing precision to 0.

1) Overwrite lib/Zend/Currency.php and change precision around line:

 69     protected $_options = array(
 70         'position'  => self::STANDARD,
 71         'script'    => null,
 72         'format'    => null,
 73         'display'   => self::NO_SYMBOL,
 74         'precision' => 0,    /*CHANGE*/
 75         'name'      => null,
 76         'currency'  => null,
 77         'symbol'    => null,
 78         'locale'    => null,
 79         'value'     => 0,
 80         'service'   => null,
 81         'tag'       => 'Zend_Locale'
 82     );

2) overwrite app/code/core/Mage/Core/Model/Store.php and change roundPrice function:

public function roundPrice($price)
{    
    return round($price, 4);
}

3) overwrite app/code/core/Mage/Directory/Model/Currency.php and change format function:

public function format($price,
                            $options=array(),
                            $includeContainer = true,
                            $addBrackets = false)
{   
  return $this->formatPrecision( $price,
                                      4,
                                      $options,
                                      $includeContainer,
                                      $addBrackets);
}

Solution 2

All answers here involve changing the core files. This is NOT what anyone should do. Either you develop a module and make those changes or you leave the core files like that and change the prices with str_replace.

So go into theme/template/catalog/product/price.phtml and (depending on configuration) around line 209 change this:

$_coreHelper->formatPrice($_price, true)

into

$without_decimals = $_coreHelper->formatPrice($_price, true); echo str_replace(".00", "", $without_decimals); 

This removes .00 from the price. The good thing is that the prices with other decimals are kept. If you don't want this you can remove everything after the dot and round the number up with round() function.

Depending on configuration other prices might need the change (if you show prices without taxes etc.)

Solution 3

To remove the decimal part from price, you need to modify the file "code/core/Mage/Directory/Model/Currency.php"

First, instead of the line:

return $this->formatPrecision($price, 2, $options, $includeContainer, $addBrackets);

use:

return $this->formatPrecision($price, 0, $options, $includeContainer, $addBrackets);

To change the position of the currency symbol, modify the file "lib/Zend/Locale/Data/en.xml" with the line:

<pattern>#,##0.00 ¤;(#,##0.00 ¤)</pattern>

When done, don't forget to clear cache.

P.S. To avoid any issues during the upgrade, we strongly recommend you to implement all the above mentioned changes via extensions: (check the tools here: http://www.magentocommerce.com/magento-connect/catalogsearch/result/?id=&s=7&pl=0&eb=0&hp=0&q=currency|position&t=1&p=1)

Solution 4

To remove the decimal part from price, you need to modify the file:

1) First is to change precision around line

lib/Zend/Currency.php

protected $_options = array(
    'position'  => self::STANDARD,
    'script'    => null,
    'format'    => null,
    'display'   => self::NO_SYMBOL,
    'precision' => 2,
    'name'      => null,
    'currency'  => null,
    'symbol'    => null,
    'locale'    => null,
    'value'     => 0,
    'service'   => null,
    'tag'       => 'Zend_Locale'
);

Change= 'precision' => 2, to 'precision' => 0,

2) Second file (change roundPrice function:)

app/code/core/Mage/Core/Model/Store.php

public function roundPrice($price)
{
    return round($price, 2);
}

To

public function roundPrice($price)
{
    return round($price, 0);
}

3) Third and last is to change format function:

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

public function format($price,
                        $options=array(),
                        $includeContainer = true,
                        $addBrackets = false)
{   
 return $this->formatPrecision( $price,
                                  2,
                                  $options,
                                  $includeContainer,
                                  $addBrackets);
}

TO

public function format($price,
                        $options=array(),
                        $includeContainer = true,
                        $addBrackets = false)
 {   
 return $this->formatPrecision( $price,
                                  0,
                                  $options,
                                  $includeContainer,
                                  $addBrackets);
 }
Share:
20,490
rramiii
Author by

rramiii

Updated on July 22, 2022

Comments

  • rramiii
    rramiii almost 2 years

    all I found in my search is a programming solution for this. I know that we can modify /lib/Zend/Locale/Data/en.xml for english stores. there was in en.xml this part:

           <currencyFormats>
                <currencyFormatLength>
                    <currencyFormat>
                        <pattern>#,##0.00 ¤</pattern>
                    </currencyFormat>
                </currencyFormatLength>
            </currencyFormats>
    

    And the price was displaying in this format: 1,321.54 now to remove the decimal part from price I think the only thing I have to do is change en.xml to be like the following:

    <currencyFormats>
                <currencyFormatLength>
                    <currencyFormat>
                        <pattern>#,##0 ¤</pattern>
                    </currencyFormat>
                </currencyFormatLength>
            </currencyFormats>
    

    The problem is after this change the prices are show as desired (1,132 Format) but without currency symbol ($). what I'm missing here?? Thanks in advance.


    update I'm still trying, when pattern node changed to the following

    <pattern>¤ #,##0</pattern>
    

    the prices are coming with currency symbol ($ 1,132) but not in desired position O_O, the requirement is to have currency symbol on the right side no left :( SO..

  • rramiii
    rramiii over 9 years
    Thank you, I think this is the only way .. but can I make sure all prices are ceil value in view and all checkout process??
  • rramiii
    rramiii over 9 years
    instead of 4 you have to use 0 other wise will have 4 decimal digits.
  • rramiii
    rramiii almost 9 years
    I think this bit wrong because it's not about only viewing price without decimal, if I follow your way, magento will make order taking price without round and on front end will be rounded price. isn't it?
  • Claudiu Creanga
    Claudiu Creanga almost 9 years
    @rramiii if you have values other than 0 as decimals you would have to implement this change also in ajax add to cart so that those prices are kept the same during checkout. But I don't understand why someone would have insert a price as 56.89 and want it to show on frontend as 57. just make it in the backend as 57.
  • aeu
    aeu over 7 years
    There's a couple of reasons this won't work. 1. It will only work with prices that end in .00. So it won't work when products are on sale and you get decimal values for prices. 2. It will not work for configurable products. While the prices for come from the helper, they get replaced by javascript with the contents of the JSON array Product.OptionsPrice, which is created in getJsonConfig.
  • Vinh VO
    Vinh VO almost 6 years
    You're right about overwritting the core files, but in FR, they use format , instead of .