A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Numerical sort issue...

  1. #1
    Member
    Join Date
    Feb 2007
    Posts
    50

    Numerical sort issue...

    Hi.

    I defined an array construct and assigned two variables to part of the array so I can simple sort it:


    number1 = array[i]
    number2 = array[i+1]

    if(number1 > number2){

    ...swap etc


    Problem is, when I try the comparason if the one of the numbers has a higher digit value, it ignores the statement entirely. Eg If 16 > 8 it skips it. So I tried adding '16' and '08' into the array and that worked perfectly with the statement.


    Any ideas?


    Thanks guys

  2. #2
    Senior Member
    Join Date
    Oct 2008
    Posts
    227
    It might treat number1 and/or number2 as strings. Hard to tell without your complete code.
    Anyway, if that's the case, try this:

    PHP Code:
    if(Number(number1) > Number(number2)){ 

  3. #3
    Member
    Join Date
    Feb 2007
    Posts
    50
    awesome that worked, thank you

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center