Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Longs losing accuracy

I just wrote the following code to convert hours and minutes to decimal
numbers. This is a test run to prepare for the real deal so it's kind
of ugly. The problem is that the variable "min" which is declaired as
a LONG is only giving me back whole numbers. What do I do to stop
that??? Thanks in advance - Pikus

Private Sub Test_Click()
Dim wd As String
Dim time As Long
Dim hr As Long
Dim min As Long

wd = "Saturday"

Do
y = y + 1
Loop Until Worksheets(wd).Cells(y + 1, 1).Value = ""

For x = 1 To y
Worksheets(wd).Cells(x, 4).Value = "=HOUR(C" & x & ")"
hr = Worksheets(wd).Cells(x, 4).Value
Worksheets(wd).Cells(x, 5).Value = "=MINUTE(C" & x & ")"
min = Worksheets(wd).Cells(x, 5).Value
min = min / 60
Worksheets(wd).Cells(x, 6).Value = min
time = hr + min
Worksheets(wd).Cells(x, 7).Value = time
Next x

End Sub


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Longs losing accuracy

Long is an expanded form of Integer. For greater precision you need to use
Single or Double.

--

Vasant


"pikus" wrote in message
...
I just wrote the following code to convert hours and minutes to decimal
numbers. This is a test run to prepare for the real deal so it's kind
of ugly. The problem is that the variable "min" which is declaired as
a LONG is only giving me back whole numbers. What do I do to stop
that??? Thanks in advance - Pikus

Private Sub Test_Click()
Dim wd As String
Dim time As Long
Dim hr As Long
Dim min As Long

wd = "Saturday"

Do
y = y + 1
Loop Until Worksheets(wd).Cells(y + 1, 1).Value = ""

For x = 1 To y
Worksheets(wd).Cells(x, 4).Value = "=HOUR(C" & x & ")"
hr = Worksheets(wd).Cells(x, 4).Value
Worksheets(wd).Cells(x, 5).Value = "=MINUTE(C" & x & ")"
min = Worksheets(wd).Cells(x, 5).Value
min = min / 60
Worksheets(wd).Cells(x, 6).Value = min
time = hr + min
Worksheets(wd).Cells(x, 7).Value = time
Next x

End Sub


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Longs losing accuracy

DOH!

Damn. You're right.

I feel like an idiot.

Thanks very much. - Pikus


---
Message posted from http://www.ExcelForum.com/

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
Accuracy Ad Pronk Excel Discussion (Misc queries) 7 December 5th 09 10:06 AM
Convert Lats and longs to decimals dharmik Excel Worksheet Functions 2 March 30th 06 07:48 PM
convert lats and longs to decimals dharmik Excel Worksheet Functions 1 March 28th 06 07:12 PM
Data Accuracy Nicole Excel Discussion (Misc queries) 0 March 28th 06 04:56 PM
Accuracy Vyyk Excel Programming 1 September 17th 03 01:07 PM


All times are GMT +1. The time now is 11:26 AM.

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

About Us

"It's about Microsoft Excel"