Wie kann die Funktion NumberFormatter::formatCurrency in PHP genutzt werden, um das Dezimalproblem bei der Preisformatierung zu lösen?
When formatting currency in PHP, the NumberFormatter::formatCurrency function can be used to solve the decimal problem by specifying the number of decimal places to display. By setting the NumberFormatter::FRACTION_DIGITS attribute to the desired number of decimal places, the formatted currency will display the correct amount of decimals.
$amount = 1234.56;
$fmt = new NumberFormatter('en_US', NumberFormatter::CURRENCY);
$fmt->setAttribute(NumberFormatter::FRACTION_DIGITS, 2);
echo $fmt->formatCurrency($amount, 'USD'); // Output: $1,234.56