awk sum giving incorrect value

 
cat T|awk -v format=$format '{ SUM += $1} END { printf format,SUM}'

the file T has below data

 
usghrt45tf:hrguat:/home/hrguat $ cat T
-1363000.00123456789
-95000.00789456123
-986000.0045612378
-594000.0015978
-368939.54159753258415
-310259.0578945612
-133197.37123456789
-12475383.16789456123
-2812276.0312345678

the output of above command is "-19138055.18514395505190" with format set to

format='%22.14f'

the actual result of the sum should be "-19138055.18514395762415"
It looks like the unix is approximating the last 6 digits in the scale. Could any one please help ?

Try:

sum=0;while read n; do sum=`echo "scale=14;$sum+$n"| bc`; done < T; echo $sum
sum=0;while read n; do sum=`echo "scale=14;$sum+$n"| bc`; done < T; echo $sum

this works but the only point which holds me back is, the above should iterate for each record and might be time consuming when there huge number of records.

Try:

awk '{$1=$1}1' OFS=+ RS=X infile | bc

or to specify a precise precision:

awk 'BEGIN{print "scale=14; "} {$1=$1}1' OFS=+ RS= infile

The result is same as cat on the file name, guess something is missing