Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

printf() With Locale

<?php

setlocale(LC_ALL, 'de_DE');
printf("%.2F ", 1000 + M_PI);  // 3.14
printf("%.2f ", 1000 + M_PI);  // 3,14

The use of locale in PHP code has lowered since PHP 8.0, where casting decimal numbers dropped the support of the numeric locale.

When that behavior is still needed, there is one place where it still exists: the print() family of functions where the f and F formats provide support for the locale-sensitive and the locale-insensitive display of numbers.

Of course, there is also the intl extension to handle these in a modern way.

print() is the last family of function where the locale are used. Before PHP 8.0, locale were used anytime a decimal to string conversion was performed by PHP, silently or not.

See Also

PHP Features

Last updated: 11 October 2026