简体   繁体   中英

How To Remove Decimal From Magento-1 Prices?

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..

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.)

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);
}

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.

PS 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 )

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);
 }

You can do one more change addition to the above all.

Please go to the PriceCurrency.php page then change the last line to

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

after that in the PriceCurrencyInterface.php page make

const DEFAULT_PRECISION = 0;

at the top.

That's all. Hope it will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM