#46267 [Opn]: mismatch between sscanf and localeconv

From: Date: Fri, 10 Oct 2008 00:43:23 +0000
Subject: #46267 [Opn]: mismatch between sscanf and localeconv
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-129598@lists.php.net to get a copy of this message
 ID:               46267
 User updated by:  oswald at jaskolla dot net
 Reported By:      oswald at jaskolla dot net
 Status:           Open
 Bug Type:         Strings related
 Operating System: Windows XP, Linux
 PHP Version:      5.2.6
 New Comment:

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: &pi; &asymp; ', $value[0], '</div>';
echo '<div>formatted: &pi; &asymp; '; printf('%f', 3.14159265);
echo
'</div>';

Expected result:
----------------
parsed: &#960; &#8776; 3.14159265
formatted: &#960; &#8776; 3,14159265

Actual result:
--------------
parsed: &#960; &#8776; 3
formatted: &#960; &#8776; 3,14159265


Previous Comments:
------------------------------------------------------------------------

[2008-10-10 00:40:06] 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: &pi; &asymp;', $value[0], '</div>';
echo '<div>formatted: &pi; &asymp;'; printf('%f', 3.14159265);
echo
'</div>';


Expected result:
----------------
parsed: &#960; &#8776;3.14159265
formatted: &#960; &#8776;3,14159265

Actual result:
--------------
parsed: &#960; &#8776;3
formatted: &#960; &#8776;3,14159265



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=46267&edit=1



Thread (4 messages)

« previous php.bugs (#129598) next »