awk: round output or delimit output of arithmatic string

I have a file with the following content.

> cat /tmp/internetusage.txt
6709.296322 30000 2/7/2010 0.00

I am using the following awk command to calculate a percentage from field 1 and 2 from the file.

awk '{ print $1/$2*100 }' /tmp/internetusage.txt

This outputs the value "22.3643" as a percent but I want to just round it to 22.

I realise I could use cut or another awk using "." as the delimiter to achieve this but I would like to just use one awk command if possible. My googling has not been successful in finding a solution.

Thanks

Hi.

Use printf instead of print

$ awk '{ printf "%d\n", $1/$2*100 }' /tmp/internetusage.txt
22
1 Like