What are the best practices for handling localization and formatting of decimal values in PHP applications?

When handling localization and formatting of decimal values in PHP applications, it is important to use the appropriate functions to ensure consistency and accuracy across different locales. One common approach is to use the number_format() function to format decimal values based on the desired locale settings. Additionally, the setlocale() function can be used to set the desired locale for number formatting.

// Set the desired locale for number formatting
setlocale(LC_ALL, 'en_US.UTF-8');

// Format a decimal value with two decimal places
$decimalValue = 1234.5678;
$formattedValue = number_format($decimalValue, 2);

echo $formattedValue; // Output: 1,234.57