Project

General

Profile

Actions

Bug #2254

open

printf should recognize floating point argument in non-C locale

Added by Alexander Eremin over 9 years ago. Updated over 9 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
cmd - userland programs
Start date:
2012-03-07
Due date:
% Done:

0%

Estimated time:
Difficulty:
Medium
Tags:
needs-triage
Gerrit CR:

Description

/bin/printf fails with floating point argument in non-C locale:
$ locale
LANG=C
LC_CTYPE=C
LC_NUMERIC=C
LC_TIME=C
LC_COLLATE=C
LC_MONETARY=C
LC_MESSAGES=C
LC_ALL=
$ /bin/printf pi=%f 3.1415
pi=3.141500

$ locale
LANG=de_DE.UTF-8
LC_CTYPE="de_DE.UTF-8"
LC_NUMERIC="de_DE.UTF-8"
LC_TIME="de_DE.UTF-8"
LC_COLLATE="de_DE.UTF-8"
LC_MONETARY="de_DE.UTF-8"
LC_MESSAGES="de_DE.UTF-8"
LC_ALL=
$ /bin/printf pi=%f 3.1415
printf: 3.1415: not completely converted
pi=3,000000~$

same story for printf from ksh93 in "de" locale:
~$ printf pi=%f 3.1415
pi=ksh93: printf: 3.1415: arithmetic syntax error
ksh93: printf: 3.1415: arithmetic syntax error
ksh93: printf: warning: invalid argument of type f
3,000000

Actions #1

Updated by Andrew Stormont over 9 years ago

That's not right. LC_NUMERIC should effect the output of printf: http://pubs.opengroup.org/onlinepubs/007904975/utilities/printf.html

Actions #2

Updated by Igor Pashev over 9 years ago

Andrew Stormont wrote:

That's not right. LC_NUMERIC should effect the output of printf: http://pubs.opengroup.org/onlinepubs/007904975/utilities/printf.html

I guess, Alex is talking about input, not output.

# export LANG=ru_RU.UTF-8
# /usr/bin/printf pi=%f 3.1415
pi=3,141500

# export LANG=C
# /usr/bin/printf pi=%f 3.1415
pi=3.141500
Actions #3

Updated by Yuri Pankov over 9 years ago

Igor Pashev wrote:

Andrew Stormont wrote:

That's not right. LC_NUMERIC should effect the output of printf: http://pubs.opengroup.org/onlinepubs/007904975/utilities/printf.html

I guess, Alex is talking about input, not output.

[...]

Indeed, input should confirm to locale, that's why issue should be rejected.

Actions #4

Updated by Igor Pashev over 9 years ago

Actually, standard does not say explicitly about input. In any case this utility (printf) is crazy since it already expects formatted input, not raw data as printf() in C. From my point, it should always accept period (.) and locale specific decimal point (maybe comma). This is a question of usability.

Actions #5

Updated by Alexander Eremin over 9 years ago

/usr/gnu/bin/printf doesn't have this problem, so I guess illumos printf shoud be fixed somehow

Actions #6

Updated by Alexander Eremin over 9 years ago

  • Subject changed from printf should not be locale sensitive to printf should recognize floating point argument in non-C locale
Actions

Also available in: Atom PDF