msmith11 Posted November 9, 2015 Share Posted November 9, 2015 Sorting negative decimals with _ArraySort has me baffled. Trying to sort a 2D array with negative decimals read in thru _FileReadToArray. Works fine for positive decimals. For negative decimals preceded by a minus sign however, _ArraySort treats negative decimals as absolute values. The minus sign seems to be ignored.Any suggestions would be greatly appreciated. Thanks and best to you.The _FileReadToArray Version:Copy this data to an empty Notepad file and save as Test.csvCALD,0.0376AXGN,0.0195ERII,-0.0243QRVO,-0.0025BLDR,-0.0059WTW,0.0620;Program start#include <File.au3>Local $avArray[6][2] _FileReadToArray( "..path\Test.csv", $avArray, 0, "," ) ;YOU'll HAVE TO MODIFY YOUR PATH HERE_ArrayDisplay($avArray) ;starting data structure _ArraySort($avArray,0,0,0,1) ;sort ascending on column 1 (the decimals)_ArrayDisplay($avArray) _ArraySort($avArray,1,0,0,1) ;sort descending on column 1 (the decimals)_ArrayDisplay($avArray);Program End;Negative Decimal Data acquired thru the UDF _FileReadToArray will not sort correctly**********************************************************************************************************The same program with data entered manually:#include <File.au3>Local $avArray[6][2] = [ _ ["CALD", 0.0376], _ ["AXGN", 0.0195], _ ["ERII", -0.0243], _ ["QRVO", -0.0025], _ ["BLDR", -0.0059], _ ["WTW", 0.062]]_ArrayDisplay($avArray) ;starting data structure _ArraySort($avArray,0,0,0,1)_ArrayDisplay($avArray) _ArraySort($avArray,1,0,0,1)_ArrayDisplay($avArray);Manually entered negative decimals sort correctly Link to comment Share on other sites More sharing options...
msmith11 Posted November 9, 2015 Author Share Posted November 9, 2015 I found something that works. Once the decimals are isolated in their own cells you can datatype them to numbers using the Number function. ;New code: #include <File.au3> Local $avArray[6][2] _FileReadToArray( "..path\Test.csv", $avArray, 0, "," ) ;YOU'll HAVE TO MODIFY YOUR PATH HERE _ArrayDisplay($avArray) ;starting data structure For $i = 0 to 5 $a_AccumArray[$i][1] = Number( $a_AccumArray[$i][1] ) Next _ArraySort($avArray,0,0,0,1) ;sort ascending on column 1 (the decimals) _ArrayDisplay($avArray) _ArraySort($avArray,1,0,0,1) ;sort descending on column 1 (the decimals) _ArrayDisplay($avArray) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 9, 2015 Moderators Share Posted November 9, 2015 msmith11,you can datatype them to numbersThat is the only way to get numbers to sort "correctly" - otherwise they are sorted as strings.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now