QuickSort and Decimals - Help Needed

Results 1 to 2 of 2

Thread: QuickSort and Decimals - Help Needed

  1. #1
    Jon Guest

    Default QuickSort and Decimals - Help Needed

    Hello,<BR> I am trying to use the quicksort method (vb version) that I found on this site. For some reason, it sorts ok until it gets to place settings. It sorts like this...<BR>1.2,1.3,10.1,12.4,2.1,2.4,21.3,200.1<BR ><BR>Any way to fix this so it goes numerically?<BR><BR>Thanks!

  2. #2
    Join Date
    Dec 1969

    Default RE: QuickSort and Decimals - Help Needed

    The problem is that VBScript doesn&#039t enforce any particular datatype in an array, and if you don&#039t say otherwise you&#039ll quite possibly end up with strings in the elements of the array.<BR><BR>You can fix this two ways:<BR><BR>(1) As you put the info to be sorted *into* the array be sure to do <BR>&nbsp;&nbsp;&nbsp;&nbsp;arrayName(elementNumbe r) = CDbl( value )<BR>That is, force all the elements to be "double" (floating point numbers).<BR><BR>(2) At the point in your code where you do the comparisons between elements, use CDbl on each element to enforce a numerical (instead of string) comparison.<BR><BR>**********<BR><BR>(2) will be *much* slower, so don&#039t use it unless you have some other reason (e.g., if the fields really contained "34 socks" and "7.5 sweaters" and you wanted to compare the numerical parts but ignore the text parts?).<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts