Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting numbers with decimal points Trish Excel Worksheet Functions 1 January 2nd 08 05:09 PM
Dollars to text without loosing zeros from decimal places DOK Excel Worksheet Functions 5 December 13th 07 05:42 PM
decimal sorting Tamesh Excel Discussion (Misc queries) 3 June 8th 06 09:46 PM
Loosing correct hyperlnk location after sorting spreadsheet data LostnSpace Excel Discussion (Misc queries) 2 February 2nd 06 10:15 PM
sorting numbers more than one decimal Erin Excel Worksheet Functions 4 March 9th 05 07:19 PM


All times are GMT +1. The time now is 10:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"