Jump to content

_ArraySort trouble


Memories
 Share

Recommended Posts

Hi.

Here is an example - 2 arrays, 1st is array of numbers, it sorts correctly, 2nd is array of same numbers, but declared as strings. It sorts uncorrectly.

What should I do with $array_str to sort it correctly? I mean - like numbers. I tried to Number(my array) successfully, but it doesn't help.

#include <array.au3>
Dim $array_num[8] = [93999998.98,94000000.01,95000000.0,95000000.01,99999998.99,100000000.0,107100002.0,117889900.0]
Dim $array_str[8] = ["93999998.98","94000000.01","95000000.0","95000000.01","99999998.99","100000000.0","107100002.0","17889900.0"]
_ArraySort ($array_num,0,0,0, 0)
_ArraySort ($array_str,0,0,0, 0)
_ArrayDisplay($array_num,"Correct sort - Numeric")
_ArrayDisplay($array_str,"Not correct sort - Strings")

For $i=0 to 7
    If IsNumber($array_num[$i])=1 then
        $array_num[$i]=Number($array_num[$i])
    EndIf
Next
_ArraySort ($array_str,0,0,0, 0)
_ArrayDisplay($array_str,"Still not correct - String=>Number")
Link to comment
Share on other sites

  • Developers

you mean something like this?:

#include <array.au3>
Dim $array_num[8] = [93999998.98,94000000.01,95000000.0,95000000.01,99999998.99,100000000.0,107100002.0,117889900.0]
Dim $array_str[8] = ["93999998.98","94000000.01","95000000.0","95000000.01","99999998.99","100000000.0","107100002.0","17889900.0"]
_ArraySort ($array_num,0,0,0, 0)
_ArraySort ($array_str,0,0,0, 0)
_ArrayDisplay($array_num,"Correct sort - Numeric")
_ArrayDisplay($array_str,"Not correct sort - Strings")

For $i=0 to UBound($array_str)-1
    $array_str[$i]=Number($array_str[$i])
Next
_ArraySort ($array_str,0,0,0, 0)
_ArrayDisplay($array_str,"correected - String=>Number")

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • 5 months later...

you mean something like this?:

#include <array.au3>
Dim $array_num[8] = [93999998.98,94000000.01,95000000.0,95000000.01,99999998.99,100000000.0,107100002.0,117889900.0]
Dim $array_str[8] = ["93999998.98","94000000.01","95000000.0","95000000.01","99999998.99","100000000.0","107100002.0","17889900.0"]
_ArraySort ($array_num,0,0,0, 0)
_ArraySort ($array_str,0,0,0, 0)
_ArrayDisplay($array_num,"Correct sort - Numeric")
_ArrayDisplay($array_str,"Not correct sort - Strings")

For $i=0 to UBound($array_str)-1
    $array_str[$i]=Number($array_str[$i])
Next
_ArraySort ($array_str,0,0,0, 0)
_ArrayDisplay($array_str,"correected - String=>Number")

Thanks, this was just what I needed.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...