1

Consider the following command in a bash terminal :

echo 0.00027849383762390271 | awk '{print sprintf("%.20f",$1)}'

I'm connected to two machines.

The first has GNU Bash version 4.15 and GNU Awk version 3.1.7. The above command returns what is expected : 0.00027849383762390268 (although the last two digits are different from my initial number)

The second machine has GNU Bash version 3.2.39 and GNU Awk version 3.1.5. The above command returns : 0,00000000000000000000 (20 zeros after the comma). Note the ',' instead of a '.' .

Why does the second machine behave differently than the first, and how to make it behaves like the first machine ?

Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125
dada
  • 1,390
  • 2
  • 17
  • 40

1 Answers1

3

Your locale is different between the 2 machines. Set LC_ALL=C (or whatever locale you want) before executing both commands and see https://www.gnu.org/software/gawk/manual/html_node/Locale-influences-conversions.html for more information.

Ed Morton
  • 188,023
  • 17
  • 78
  • 185
  • I ssh to both machines from the same local computer. So why do they behave differently ? Is there some variable that is set differently in the machines ? By the way, setting the LC_ALL as you suggested worked. Here's the entire command : `echo 0.00027849383762390271 | LC_ALL=C awk '{print sprintf("%.20f",$1)}'` – dada May 02 '16 at 20:02
  • Yes there's some variable or config file but idk where/what. Google `locale` to start to debug. Run `env` on both machines and look for differences, etc... – Ed Morton May 02 '16 at 20:14