PC Review


Reply
Thread Tools Rate Thread

Floating Point Math Problem

 
 
Joe
Guest
Posts: n/a
 
      8th Jul 2009
I am attempting to solve a simple floating point math problem
and I am not getting the results that I think I should be getting.
Here is what I am doing:

Dim iMinutes As Integer
Dim dHours, dMinutes, dUnits As Double

iMinutes = DateDiff(DateInterval.Minute, dStartTime,
dEndTime)
dHours = iMinutes \ 60
dMinutes = iMinutes Mod 60
dUnits = dHours + (dMinutes \ 60.0)

My input start time is 9:00AM and my ending time is 10:15AM

dHours = 1 (good)
dMinutes = 15 (good)
dUnits = 1 (not good, should be 1.25)

Can someone tell me what I am doing wrong? It seems like I cannot
get any numbers to the right of the decimal point for dUnits.

 
Reply With Quote
 
 
 
 
Stephany Young
Guest
Posts: n/a
 
      8th Jul 2009
You're NOT using the divide operator for floating point math.

You're using the division operator for integer math.

Use the / operator instead of the \ operator.


"Joe" <(E-Mail Removed)> wrote in message
news:c2e7a6ac-79f3-43ee-8d47-(E-Mail Removed)...
> I am attempting to solve a simple floating point math problem
> and I am not getting the results that I think I should be getting.
> Here is what I am doing:
>
> Dim iMinutes As Integer
> Dim dHours, dMinutes, dUnits As Double
>
> iMinutes = DateDiff(DateInterval.Minute, dStartTime,
> dEndTime)
> dHours = iMinutes \ 60
> dMinutes = iMinutes Mod 60
> dUnits = dHours + (dMinutes \ 60.0)
>
> My input start time is 9:00AM and my ending time is 10:15AM
>
> dHours = 1 (good)
> dMinutes = 15 (good)
> dUnits = 1 (not good, should be 1.25)
>
> Can someone tell me what I am doing wrong? It seems like I cannot
> get any numbers to the right of the decimal point for dUnits.
>


 
Reply With Quote
 
Family Tree Mike
Guest
Posts: n/a
 
      8th Jul 2009
Joe wrote:
> I am attempting to solve a simple floating point math problem
> and I am not getting the results that I think I should be getting.
> Here is what I am doing:
>
> Dim iMinutes As Integer
> Dim dHours, dMinutes, dUnits As Double
>
> iMinutes = DateDiff(DateInterval.Minute, dStartTime,
> dEndTime)
> dHours = iMinutes \ 60
> dMinutes = iMinutes Mod 60
> dUnits = dHours + (dMinutes \ 60.0)
>
> My input start time is 9:00AM and my ending time is 10:15AM
>
> dHours = 1 (good)
> dMinutes = 15 (good)
> dUnits = 1 (not good, should be 1.25)
>
> Can someone tell me what I am doing wrong? It seems like I cannot
> get any numbers to the right of the decimal point for dUnits.
>


I think that dEndTime.Subtract(dStartTime).TotalHours is simpler.

--
Mike
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Field Definitions - problem with floating point calculations dhstein Microsoft Access 4 8th Feb 2009 05:36 PM
Floating Point Calculation Problem =?Utf-8?B?REo=?= Microsoft Dot NET Framework 3 1st Oct 2006 06:12 AM
excel math forumla? (simple math problem inside for math people!) Jason Microsoft Excel Discussion 3 16th Feb 2006 11:54 AM
Floating point problem?? Frederick Chow Microsoft Excel Programming 6 3rd Jan 2006 04:39 AM
Floating point problem ..................... Hiten Microsoft C# .NET 7 3rd Aug 2005 07:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:36 PM.