Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

floating point problem. newbie

Status
Not open for further replies.

moealcoi

Programmer
Apr 19, 2005
1
ES
When I run this simple awk program i'm getting confusing results. Why in the 3rd execution awk is always printing 0?

$ gawk '{ printf("%10.6f %10.6f %10.6f\n",$1,$2,$1-$2)}'
3,6 3,6
3,600000 3,600000 0,000000
3,5 3,0
3,500000 3,000000 0,500000
0,6 0,3
0,000000 0,000000 0,000000

$ gawk --version
GNU Awk 3.1.3

Thank you very much!
Miguel
 
That does indeed seem strange.

Code:
test.txt
--------
3,6 3,6    <- , as dec. point
3.6 3.6    <- . as dec. point
3,5 3,0
3.5 3.0
0,6 0,3
0.6 0.3
--------

test.awk
--------
{ printf("%10.1f %10.1f %10.1f\n",$1,$2,$1-$2) }
--------

>gawk -f test.awk test.txt
3,600000   3,600000   0,000000
3,000000   3,000000   0,000000
3,500000   3,000000   0,500000
3,000000   3,000000   0,000000
0,600000   0,300000   0,300000
0,000000   0,000000   0,000000

Works fine for me.

gawk 3.1.3 on Windows, Danish locale

- Nis Donatzsky
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top