The setlocale
, localeconv
, and related functions do not work with Unicode CLDR locale identifiers or data. Instead, they vary per operating system, with POSIX locale identifiers and data on *nix systems and Microsoft locale strings and data on Windows.
# works only on Linux after running `locale-gen de_DE.UTF-8`
# but Windows requires an entirely different locale identifier
setlocale(LC_ALL, 'de_DE.UTF-8');
$locale = localeconv();
echo number_format(
1234.5,
1, # fraction digits
$locale['decimal_point'],
$locale['thousands_sep']
); # '1.234,5'
If you’d actually like to use Unicode CLDR locale identifiers and data for a unified experience regardless of your operating system, use the International extension instead. It’s available with PHP 5.3 and is a wrapper around the ICU (International Components for Unicode) library, which provides standardized CLDR locale data.
$fmt = new NumberFormatter('de-DE', NumberFormatter::DECIMAL); # or 'de_DE'
echo $fmt->format(1234.5); # '1.234,5'