Magento – Magneto 2: Need to remove decimal from price on product detail page

magento2priceproduct-detail-page

I want to remove the decimal in price on product details page. Although it removes in listing page, but still showing decimal in discount and final price on product details page.

enter image description here

Best Answer

Create file and use this code :

=> From :

vendor/magento/module-catalog/view/base/templates/product/price/amount/default.phtml

=> To :

app/design/frontend/VendorName/ModuleName/Magento_Catalog/templates/product/price/amount/default.phtml

this file is defined from \Magento\Framework\Pricing\Render\Amount

The price itself is coming from this call:

<?php /* @escapeNotVerified */ echo $block->formatCurrency($block->getDisplayValue(), (bool)$block->getIncludeContainer()) ?>

If we take a look at the file that this method is created based on the class it's inheriting (/vendor/magento/framework/Pricing/Render/Amount.php)

Update line no 24

<?php /* @escapeNotVerified */ echo $block->formatCurrency($block->getDisplayValue(), (bool)$block->getIncludeContainer()) ?>

To

<?php /* @escapeNotVerified */ echo $block->formatCurrency($block->getDisplayValue(), (bool)$block->getIncludeContainer() , 0) ?>

You need to override

vendor/magento/module-catalog/view/base/web/js/price-utils.js

To

app/design/frontend/VendorName/ModuelName/Magento_Catalog/web/js/price-utils.js

and change the value of precision on line 38:

var precision = isNaN(format.requiredPrecision = Math.abs(format.requiredPrecision)) ? 2 : format.requiredPrecision,

To

var precision = 0,
Related Topic