Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
loosing decimal upon sorting?
Hi all, Hope someone can help with this problem I use a dynamic array of Long type to keep som values in so that I ca sort them later. The problem is that when I list the values afte sorting them, the decimal value is lost; e.g 204,5 becomes 204,0 (al values have a zero after the decimal point) I do Dim myArr() As Long ReDim Preserve myArr(0 To counter) myArr(counter) = _ Worksheets("Sheet1").Range("A" & counter).Value ' Call sort(myArr) Then I use these algorithms to sort the values Sub sort(A() As Long) Dim i As Long, j As Long For i = LBound(A) To UBound(A) - 1 For j = i + 1 To UBound(A) If A(j) A(i) Then swapI A(j), A(i) End If Next j Next i End Sub Sub swapI(x As Long, y As Long) Dim tmp As Long tmp = x x = y y = tmp End Sub Can anyone help with this please -- hk ----------------------------------------------------------------------- hke's Profile: http://www.excelforum.com/member.php...nfo&userid=155 View this thread: http://www.excelforum.com/showthread.php?threadid=31931 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
loosing decimal upon sorting?
Long type variables hold only whole numbers. The decimal portion
of a number stored to a Long will be lost. Change your data types from Long to Double. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "hke" wrote in message ... Hi all, Hope someone can help with this problem I use a dynamic array of Long type to keep som values in so that I can sort them later. The problem is that when I list the values after sorting them, the decimal value is lost; e.g 204,5 becomes 204,0 (all values have a zero after the decimal point) I do Dim myArr() As Long ReDim Preserve myArr(0 To counter) myArr(counter) = _ Worksheets("Sheet1").Range("A" & counter).Value ' Call sort(myArr) Then I use these algorithms to sort the values Sub sort(A() As Long) Dim i As Long, j As Long For i = LBound(A) To UBound(A) - 1 For j = i + 1 To UBound(A) If A(j) A(i) Then swapI A(j), A(i) End If Next j Next i End Sub Sub swapI(x As Long, y As Long) Dim tmp As Long tmp = x x = y y = tmp End Sub Can anyone help with this please? -- hke ------------------------------------------------------------------------ hke's Profile: http://www.excelforum.com/member.php...fo&userid=1550 View this thread: http://www.excelforum.com/showthread...hreadid=319311 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
sorting numbers with decimal points | Excel Worksheet Functions | |||
Dollars to text without loosing zeros from decimal places | Excel Worksheet Functions | |||
decimal sorting | Excel Discussion (Misc queries) | |||
Loosing correct hyperlnk location after sorting spreadsheet data | Excel Discussion (Misc queries) | |||
sorting numbers more than one decimal | Excel Worksheet Functions |