View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default 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