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

setlocale() Does Not Affect Echo Anymore

setlocale() used to impact several functions, including echo. With the French or German (or other) conventions, the decimal separator is a comma, and PHP makes the conversion at echo time.

This is not the case anymore in PHP 8.0: anytime the float is converted to a string, the locale formatting is not applied anymore.

It is recommended to make this conversion explicit by using printf(), number_format() or a custom formatter function.

PHP code

<?php

setlocale(LC_ALL, 'fr_FR.UTF-8');

echo 1003.14;

?>

Before

1003,14

After

1003.14

PHP version change

This behavior changed in 8.0.

© 2023-2026, Damien Seguy - Exakat