[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Command line variable assignment problems with localized floats

From: Heike C. Zimmerer
Subject: Command line variable assignment problems with localized floats
Date: Fri, 22 Dec 2006 19:19:31 +0100
User-agent: Mutt/1.5.13 (2006-08-11)


I'm reporting a localization issue, checked with:

 $ gawk --version
 GNU Awk 3.1.5
 Copyright (C) 1989, 1991-2005 Free Software Foundation.

Problem 1:
 Command line non-option variable assignments of floats are incorrecty
 handled if the current locale (LC_NUMERIC) defines something else than
 a dot (".") to represent a decimal point.  (Non-option assigment means:
 awk '...{...}' var=val (as opposed to awk -v var=val '...{...}').)

 The fractional part is truncated for both "." and ",".

Problem 2:

 This is with the -v var=val form of command line assignments: Using
 this form with a different character for the decimal point yields
 about the opposite result: both characters are recognized as decimal
 point sign.

To reproduce the problem:

Locale environment:
 $ locale -a

Unless otherwise noted in the following examples, the en_US.utf8
environment is used (it's my system wide default ($LANG)).

given the following awk script (assigned to a shell variable):

  printf "a: \"%s\"->%f, b: \"%s\"->%f\n", a, a, b, b

the following results are obtained:

 $ echo | awk "$awktest" a=1.23 b=4,56
 a: "1.23"->1.230000, b: "4,56"->4.000000


 $ echo | LC_NUMERIC=de_DE.utf8 awk "$awktest" a=1.23 b=4,56
 a: "1.23"->1,000000, b: "4,56"->4,000000

Neither "." (correct) nor the now current deciaml point (",") are
recognized.  (Btw, changing the last printf argument from `b´ into 
`b ""´ (concatenation with the empty string) yields the correct result,
which seems to indicate to me that the error happens very early during the
interpretation of the command line argument).

Now to problem #2 (which is less likely to cause real problems):

 $ echo | awk -v a=1.23 -v b=1,23 "$awktest"
 a: "1.23"->1.230000, b: "1,23"->1.000000

Looks correct.

 $ echo | LC_NUMERIC=de_DE.utf8 awk -v a=1.23 -v b=1,23 "$awktest"
 a: "1.23"->1,230000, b: "1,23"->1,230000

I'd expect 1,0000 for a's numeric value.

Have nice holidays and a happy new year,


reply via email to

[Prev in Thread] Current Thread [Next in Thread]