cgoodman
Programmer
- Dec 29, 2008
- 7
Hey,
I am having an issue with awk rounding numeric variables.
My script is as follows:
The code sums up the numeric values found in specified columns (CFIELDs are hard coded into program). I am checking that the sum (SUM1, SUM2...) from the function is equal to the actual sum of the column. However, awk is rounding the values of this variables. For one file, the actual sum of the column was 128034.35, while the program computed the sum to be 128034.4.
Obviously, there is a rounding issue; however, the real question is - Is there any way around this error and why is awk rounding the numeric value when the number isn't that big?
Thanks for all help.
Chris
I am having an issue with awk rounding numeric variables.
My script is as follows:
Code:
function ControlSumSix()
{
while((getline < MYFILENAME)>0) {
COUNT = $CFIELD;
COUNT2 = $CFIELD2;
COUNT3 = $CFIELD3;
COUNT4 = $CFIELD4;
COUNT5 = $CFIELD5;
COUNT6 = $CFIELD6;
SUM += COUNT;
SUM2 += COUNT2;
SUM3 += COUNT3;
SUM4 += COUNT4;
SUM5 += COUNT5;
SUM6 += COUNT6;
}
close(MYFILENAME)
}
The code sums up the numeric values found in specified columns (CFIELDs are hard coded into program). I am checking that the sum (SUM1, SUM2...) from the function is equal to the actual sum of the column. However, awk is rounding the values of this variables. For one file, the actual sum of the column was 128034.35, while the program computed the sum to be 128034.4.
Obviously, there is a rounding issue; however, the real question is - Is there any way around this error and why is awk rounding the numeric value when the number isn't that big?
Thanks for all help.
Chris