Adding "1.123+4.242 = 5" problem

I wan't to add two numbers (e.g 1.123 and 4.242) from different files but the add operation seems to cut the decimals. Any ideas how to convert or rewrite?
(The numbers in the file are in 1.123 and not 1,123)

-------------------

awk 'NR>9{print $3,$4,$5}' rlx.4000.dump > pos_0
awk 'NR>9{print $3,$4,$5}' rlx.4050.dump > pos_1

paste pos_0 pos_1 | awk '{x0=$1+$4; y0=$2+$5; z0=$3+$6 ; print x1,y0,z0}' > pos_2

-------------------

Tommy

awk, by default, uses double precision (floating decimal) arithmetic.

Use:

 printf("%.3f %.3f %.3f\n", x1, y0, z0) 

instead of your print x1, y0, z0 print statement

That doesn't solve it. I think the problem is that the two numbers are read in with a dot decimal separator instead of a comma separator. How can I make awk keep the decimals ?

Part of your problem might be related to the fact that you assign x0 yet print x1.

awk '{x0=$1+$4; y0=$2+$5; z0=$3+$6 ; print x0,y0,z0}'

If that change doesn't help, have a look in your two intermediate files, and run your paste command, piping it to more, to see what it is producing (determine where the data is getting messed up).

awk 'END{print a[3],a[4],a[5]}FNR>9{for(i=2;i++<5;) {a+=$i}}' rlx.4000.dump rlx.4050.dump > pos_2
# echo "1.123 + 4.242" | bc
5.365