cancel
Showing results for 
Search instead for 
Did you mean: 

How can i remove ".00" (decimal place) from price range filter on layered navigation ?

How can i remove ".00" (decimal place) from price range filter on layered navigation ?

Magento Version : 2.3.0

According to my client requirement, need to remove ".00" decimal places from price range filter on category page layered navigation.

 

For that please see screenshot : 


Screenshot_1.png

 


Please suggest me, how can i achieve it ?


4 REPLIES 4

Re: How can i remove ".00" (decimal place) from price range filter on layered navigation ?

Hello @yagnik_solanki 

 

Please try the below solution:

  1. Create di.xml at app/code/YourNamespace/YourModule/etc/

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
        <preference for="Magento\Framework\Pricing\PriceCurrencyInterface"
                    type="YourNamespace\YourModule\Model\PriceCurrency" />
    </config>

  2. Create PriceCurrency.php at app/code/YourNamespace/YourModule/Model/

    <?php
    
    namespace YourNamespace\YourModule\Model;
    
    use Magento\Framework\Pricing\PriceCurrencyInterface;
    
    class PriceCurrency extends \Magento\Directory\Model\PriceCurrency implements PriceCurrencyInterface
    {
        /**
         * @inheritdoc
         */
        const PRECISION_ZERO = 0;
    
        /**
         * {@inheritdoc}
         */
        public function format(
            $amount,
            $includeContainer = true,
            $precision = self::PRECISION_ZERO,
            $scope = null,
            $currency = null
        ) {
            return $this->getCurrency($scope, $currency)
                ->formatPrecision($amount, $precision, [], $includeContainer);
        }
    }

Source: Magento 2: how to remove decimal values from layered navigation

 

Hope it helps.

---
If you've found my answer useful, please give"Kudos" and "Accept as Solution"

Re: How can i remove ".00" (decimal place) from price range filter on layered navigation ?

Thanks for reply,

I already tried this type of solution but i need to only for layered
navigation price range filter not for whole site.

can you have any other solution for this?

Re: How can i remove ".00" (decimal place) from price range filter on layered navigation ?

Please try the below solution:

 

Open the file:

vendor/magento/module-layered-navigation/view/frontend/templates/layer/filter.phtml

 

At line 23, you'll find:

 

<?= /* @escapeNotVerified */ $filterItem->getLabel() ?>

 

Replace it with:

<?php echo str_replace(".00","",$filterItem->getLabel()); ?>

 

Implement the above steps and you'll get the solution.

---
If you've found my answer useful, please give"Kudos" and "Accept as Solution"

Re: How can i remove ".00" (decimal place) from price range filter on layered navigation ?

Thanks for reply,

I have fixed issue my way.