| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2008-10-10 00:40 UTC] oswald at jaskolla dot net
 Description:
------------
sscanf() seems not to be locale-aware when interpreting '%f', even though the documentation says it is. localeconv() says that after my call to setlocale(), the comma is interpreted as decimal separator. Still everything after the comma is omitted.
Tested environments:
Windows XP, PHP 5.2.5, Apache 2.2.8 (mpm_winnt)
Linux 2.6.9, PHP 5.2.6RC1, Apache 2.2.8 (prefork)
Reproduce code:
---------------
setlocale(LC_ALL, array('de_DE.utf-8', 'german'));
$value = sscanf('3,14159265', '%f');
echo '<div>parsed: π ≈', $value[0], '</div>';
echo '<div>formatted: π ≈'; printf('%f', 3.14159265); echo '</div>';
Expected result:
----------------
parsed: π ≈3.14159265
formatted: π ≈3,14159265
Actual result:
--------------
parsed: π ≈3
formatted: π ≈3,14159265
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 08:00:01 2025 UTC | 
Description: ------------ sscanf() seems not to be locale-aware when interpreting '%f', even though the documentation says it is. localeconv() says that after my call to setlocale(), the comma is interpreted as decimal separator. Still everything after the comma is omitted. Tested environments: Windows XP, PHP 5.2.5, Apache 2.2.8 (mpm_winnt) Linux 2.6.9, PHP 5.2.6RC1, Apache 2.2.8 (prefork) Reproduce code: --------------- setlocale(LC_ALL, array('de_DE.utf-8', 'german')); $value = sscanf('3,14159265', '%f'); echo '<div>parsed: π ≈ ', $value[0], '</div>'; echo '<div>formatted: π ≈ '; printf('%f', 3.14159265); echo '</div>'; Expected result: ---------------- parsed: π ≈ 3.14159265 formatted: π ≈ 3,14159265 Actual result: -------------- parsed: π ≈ 3 formatted: π ≈ 3,14159265