i have got a flat file and it has got balance amount value as one of its fields. my mission is to add the total of those balance values. i am getting that but the result is coming up in exponential form, which is not the right way. i want to see the sum as a normal decimal number but not in expenential number. any help would be appriciated.
the code i have got is:
cut -d"|" -f10 /bx201a/pwchome0001/pcdev/server/TgtFiles/standard_csv_file1.out | awk '{ x += $1 } END { print "Sum: " x }'
thanks for the reply. i tried the both and here is the outcome:
printf("%10f", x)
i am getting something like this:
1026780823.850019bash-2.03$
two problems here.
i don't know why that $ prompt is getting attached to the value.
second problem is, the original balance has got values upto only two decimals. but the outcome has got values upto 6 decimals. i don't know where the extra 4 decimal values are coming from.
with the other code, which is:
printf("sum: %d\n", x)
i am not getting any decimal values at all. this is the output:
sum: 1026780823
the file is a huge file with millions of records in it. i can give you some sample values for that column if that helps
202.62
0.00
4678.41
etc. its a column of (9,2) precission and scale in oracle terms.so it has got 2 digits after the decimal point and 7 digits before the decimal point. further help would be appriciated.
awk uses floating point numbers, it doesn't have infinite precision. It's stored internally as a value like x * 2^n. If you want infinite precision down to the exact last decimal point, awk is the wrong tool.
Well, you never asked for any until now. Try %.2f.