diff --git a/app/code/Magento/Catalog/Pricing/Render/PriceBox.php b/app/code/Magento/Catalog/Pricing/Render/PriceBox.php index 190168ed583fc..678b45ce97e7b 100644 --- a/app/code/Magento/Catalog/Pricing/Render/PriceBox.php +++ b/app/code/Magento/Catalog/Pricing/Render/PriceBox.php @@ -3,6 +3,8 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Catalog\Pricing\Render; use Magento\Catalog\Model\Product; @@ -71,7 +73,9 @@ public function jsonEncode($valueToEncode) * * @param int $length * @param string|null $chars + * * @return string + * @throws \Magento\Framework\Exception\LocalizedException */ public function getRandomString($length, $chars = null) { @@ -93,4 +97,21 @@ public function getCanDisplayQty(Product $product) } return true; } + + /** + * Format percent + * + * @param float $percent + * + * @return string + */ + public function formatPercent(float $percent): string + { + /*First rtrim - trim zeros. So, 10.00 -> 10.*/ + /*Second rtrim - trim dot. So, 10. -> 10*/ + return rtrim( + rtrim(number_format($percent, 2), '0'), + '.' + ); + } } diff --git a/app/code/Magento/Catalog/view/base/templates/product/price/tier_prices.phtml b/app/code/Magento/Catalog/view/base/templates/product/price/tier_prices.phtml index f5cffb99d75dd..c2b7fb4e60855 100644 --- a/app/code/Magento/Catalog/view/base/templates/product/price/tier_prices.phtml +++ b/app/code/Magento/Catalog/view/base/templates/product/price/tier_prices.phtml @@ -77,7 +77,7 @@ $product = $block->getSaleableItem(); $price['price_qty'], $priceAmountBlock, $index, - $tierPriceModel->getSavePercent($price['price']) + $block->formatPercent($price['percentage_value'] ?? $tierPriceModel->getSavePercent($price['price'])) ) : __('Buy %1 for %2 each', $price['price_qty'], $priceAmountBlock); ?>