0

I have a CSV file which has data on it such as:

File           % Diff
testfile0.xml  44.948
testfile1.xml  22.232
testfile2.xml  45.343
testfile3.xml  2.345
testfile4.xml  -3.948
testfile5.xml  22.232
testfile6.xml  45.343
testfile7.xml  2.345
testfile8.xml  -3.948
testfile9.xml  90.948

I'd like to summarize this data and categorize the %diff results into 10% increments

%Grouping  No files
neg-00     2  
00-10      2
10-20      0
20-30      2
30-40      0
40-50      3
50-60      0
60-70      0
70-80      0
80-90      1
90-100     1

So essentially, how can I group doubles together in ranges of 10% increments using Java. Any help of assistance would be much appreciated.

arabian_albert
  • 708
  • 1
  • 11
  • 24
  • Take care of negatives, then [cast to int](http://stackoverflow.com/questions/9102318/cast-double-to-integer-in-java) and divide by 10? – Alex Libov Nov 03 '16 at 03:35

2 Answers2

1

If your groups are -1 to 9 then:

groupNumber = (diff<=0) ? -1 : (diff.intValue() / 10);

Alex Libov
  • 1,481
  • 2
  • 11
  • 20
1

Store the counts of the different increments in an array with 11 locations. Initialize the 11 counts to 0.

Read the double value on each line.

If the double value is negative, increment the count in the 0th index. Otherwise, truncate the double value to an integer, and then integer divide the result by 10 and add 1 to get the index of the count to increment.

David Choweller
  • 1,060
  • 1
  • 8
  • 7