Quantcast
Channel: nixCraft: Linux Tips, Hacks, Tutorials, And Ideas In Blog Format (RSS/FEED)
Viewing all articles
Browse latest Browse all 2612

Awk Floating Point Number Addition Results Are UnexpectedFrequently Asked Questions About Linux / UNIX

$
0
0
I am using awk to grep 'foo' from a text file and cacluate sum of field # 7. But, result is rounded to an integer. I need exact result such as 385858.66 and not 385858 using the following command:
grep 'foo' 2012-2013.txt | awk 'BEGIN{ sum=0.0}{ sub(",","",$7); sum +=$7}END{ print "$" sum}' $682444
I want $682444.57 as output. How can I force "awk" to do floating point math?

Read answer to: "Awk Floating Point Number Addition Results Are Unexpected"

Tweet this   Share on Facebook


Viewing all articles
Browse latest Browse all 2612

Trending Articles