Using integers isn't the only point here. The size of the sum is what matters in this problem. Since awk uses double precision floating point arithmetic (even when processing integers), you can have a problem if the accumulated sum (in cents) is 15 or more digits (i.e., more than $999,999,999.99). So, if your final result is less than 1 billion dollars, RudiC's script should be fine. If your result could be bigger, you can use shell and bc or dc to get the results you want no matter how big the sum is:
#!/bin/ksh
(echo '2k0[$]P'; while read line
do echo " $line"
done < my_file.txt
echo '100/pq') | dc
printf '$'
(echo 'a=0;scale=2'; while read line
do echo "a+=$line"
done < my_file.txt
echo 'a/100'
) | bc
On most UNIX and UNIX-like systems, bc is a front-end to dc . Therefore, I tend to use dc instead of bc to avoid creating the extra process. But, bc is in the standards and dc isn't. So, if your system doesn't have dc or you want your script to be portable to systems that might not have dc , use bc .
Both sections of the above script print:
$600.00
when your sample input is contained in my_file.txt .