Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange carry over in awk summation

Status
Not open for further replies.

cgoodman

Programmer
Dec 29, 2008
7
Hey guys,

I ran across something really odd today. I'm summing columns in a flat file, and then running an equivalence check against the cooresponding summed columns.

This is my code for the summing of the columns:
Code:
SUM1 += ($CFIELD)*100;
SUM2 += ($CFIELD2)*100;
print(SUM2);
SUM3 += ($CFIELD3)*100;
SUM4 += ($CFIELD4)*100;
SUM5 += ($CFIELD5)*100;
SUM6 += ($CFIELD6)*100;

CFIELD = 129, CFIELD2 = 128....

There is a problem with SUM2. The output from the print(SUM2) statement is as follows:
-17106.00000000000000000000000000000000000000000000000000
-34212.00000000000000000000000000000000000000000000000000
-356046.00000000000000000000000000000000000000000000000000
-407297.00000000000000000000000000000000000000000000000000
-712275.00000000000000000000000000000000000000000000000000
-944788.00000000010000000000000000000000000000000000000000

Notice that there is a 1 in the final sum, when there are no "hanging 1's" in any of the other sums. (I changed the variable OFMT to "%.50f" to check the actual value of the number)

The rest of the SUM's add as expected.

Any ideas where the "hanging 1" came from?
 
Floating point values are approximation only.
You may use the int() function.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top