From b7093f4f054e96fc190f13d05cc3614bd11184bc Mon Sep 17 00:00:00 2001 From: David Date: Fri, 6 May 2022 10:56:28 +0200 Subject: [PATCH] Remove trailing zeros from formatted price --- src/PriceFormatter.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/PriceFormatter.php b/src/PriceFormatter.php index b01010f..7768b80 100644 --- a/src/PriceFormatter.php +++ b/src/PriceFormatter.php @@ -23,6 +23,12 @@ class PriceFormatter $currency->thousandsSeparator(), ); + // Remove trailing zeros from price + $decimal = rtrim($decimal, '0'); + // If there is no more decimal values, remove the trailing decimal separator as well + $decimal = rtrim($decimal, $currency->decimalSeparator()); + + return $currency->prefix() . $decimal . $currency->suffix(); }