1 Reply Latest reply on Dec 8, 2010 7:00 AM by Maximist

    How to sort Array

    Maximist Level 1

      Hallo, i have a little problem about the sortOn method. I have an array of objects. One of those objects is prezzo which is a Number and the values are:

       

      array[0].prezzo = 12.5;

      array[0].prezzo = 13.65;

      array[0].prezzo = 21.6;

      array[0].prezzo = 22.8;

      array[0].prezzo = 33.21;

      array[0].prezzo = 33.5;

      array[0].prezzo = 50.3;

      array[0].prezzo = 80.1;

      array[0].prezzo = 85.12;

      array[0].prezzo = 9.46;

       

      I want to order this values in descent way so i am trying to use the function sortOn() in this way:

       

      array.sortOn('prezzo', Array.DESCENDING);

       

      The result is:

       

      array[0].prezzo = 9.46;

      array[0].prezzo = 85.12;

      array[0].prezzo = 80.16;

      array[0].prezzo = 50.3;

      array[0].prezzo = 33.5;

      array[0].prezzo = 33.21;

      array[0].prezzo = 22.8;

      array[0].prezzo = 21.6;

      array[0].prezzo = 13.65;

      array[0].prezzo = 12.50;

       

      It seems almost perfect... The only problem is the 9.46 at first place... Why is it there??.. 9.46 is not greater than 85.12... What is my mistake??.. Why it happen?... How can i fix it??

       

      Thx for all

       

      Max