Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Re: Sorting numeric strings (http://www.velocityreviews.com/forums/t945877-re-sorting-numeric-strings.html)

Gene Wirchenko 05-01-2012 05:30 PM

Re: Sorting numeric strings
 
On Mon, 30 Apr 2012 21:27:30 -0400, Ben <no@way.com> wrote:

>Given the following data:
>
>Col1, Col2, Col3
>438.23, 991897664, ccc
>22.12, 991897631, bbb
>100.99, 881897631, aaa
>50.12, 991884803, ddd
>
>The class below will sort the data based on the column specified,
>except Col1, which contains float values. If you set the SortCol
>variable below to 0, sorting does not work. If you set it to 1 or 2,
>sorting does work. How can I sort Col1 which is a column of numeric
>strings?


What do you mean by "sort"? What order will the first column's
data be in when sorted? This is sorted by the first column by string
value:
100.99, 881897631, aaa
22.12, 991897631, bbb
438.23, 991897664, ccc
50.12, 991884803, ddd

I suspect that you want to sort by numeric value. In that case,
you will have to convert to numeric values and sort the numeric
values.

But if, for example, leading or trailing zeroes affect the
ordering, then you will have to define an order yourself. That will
suggest how to proceed.

[snip]

Sincerely,

Gene Wirchenko


All times are GMT. The time now is 04:13 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57