cancel
Showing results for 
Search instead for 
Did you mean: 

can't showing up selling price 2 decimal places. it show ups 4 decimal place but price is correct

can't showing up selling price 2 decimal places. it show ups 4 decimal place but price is correct

I have checked Magento 2.2.3 by default showing up 4 decimal places on selling price in catalog product grid and frontend side layered navigation except for price attribute other than showing up 4 decimal places. Is that magento2 default issues? 

 

If you like my question is useful then kudos on it.

4 REPLIES 4

Re: can't showing up selling price 2 decimal places. it show ups 4 decimal place but price is correc

Hello @kamlesh_solanki1

 

By default Magento 2 showing two digits.

 

Maybe you are using other locale and it will use 4 digit, may  i know your locale?

 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: can't showing up selling price 2 decimal places. it show ups 4 decimal place but price is correc

Price showing up correct but other attribute created based on price like the special price they will display 4 decimal places in product grid admin backend

Re: can't showing up selling price 2 decimal places. it show ups 4 decimal place but price is correc

Hello ,

For price attribute you need to custom thing for Magento.

https://magento.stackexchange.com/questions/127244/getting-an-attribute-price-to-format-to-2-decimal...

Hope it will help you.

Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: can't showing up selling price 2 decimal places. it show ups 4 decimal place but price is correc

override the Ui/Component/Listing/Columns/product_listing.xml

add this code 

 

        <column name="price" class="Magento\Catalog\Ui\Component\Listing\Columns\Price" sortOrder="70">
            <settings>
                <addField>true</addField>
                <filter>textRange</filter>
                <label translate="true">Price</label>
            </settings>
        </column>
 
        <column name="special_price" class="Magento\Catalog\Ui\Component\Listing\Columns\Price" sortOrder="74">
            <settings>
                <addField>true</addField>
                <filter>textRange</filter>
                <label translate="true">Special Price</label>
            </settings>
        </column>
        <column name="weight" class="Magento\Catalog\Ui\Component\Listing\Columns\Weight" sortOrder="76">
            <settings>
                <addField>true</addField>
                <filter>textRange</filter>
                <label translate="true">Weight</label>
            </settings>
        </column>
        <column name="qty" class="Magento\Catalog\Ui\Component\Listing\Columns\Qty" sortOrder="78">
            <settings>
                <addField>true</addField>
                <filter>textRange</filter>
                <label translate="true">Qty</label>
            </settings>
        </column>

Create the module-catalog/Ui/Component/Listing/Columns/Qty.php file

    public function prepareDataSource(array $dataSource)
    {
        if (isset($dataSource['data']['items'])) {
            $store = $this->storeManager->getStore(
                $this->context->getFilterParam('store_id', \Magento\Store\Model\Store::DEFAULT_STORE_ID)
            );


            $fieldName = $this->getData('name');
            foreach ($dataSource['data']['items'] as & $item) {
                if (isset($item[$fieldName])) {
                    $item[$fieldName] = intval($item[$fieldName]);
                }
            }
        }

        return $dataSource;
    }

Create the module-catalog/Ui/Component/Listing/Columns/weight.php

    public function prepareDataSource(array $dataSource)
    {
        if (isset($dataSource['data']['items'])) {
            $store = $this->storeManager->getStore(
                $this->context->getFilterParam('store_id', \Magento\Store\Model\Store::DEFAULT_STORE_ID)
            );


            $fieldName = $this->getData('name');
            foreach ($dataSource['data']['items'] as & $item) {
                if (isset($item[$fieldName])) {
                    $item[$fieldName] = number_format($item[$fieldName], 2);
                }
            }
        }

        return $dataSource;
    }