|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Floating Point Math Problemand 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. 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. Show quoteHide quote "Joe" <delphi***@cox.net> wrote in message news:c2e7a6ac-79f3-43ee-8d47-c4680d3b1d04@g31g2000yqc.googlegroups.com... > 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. > Joe wrote:
Show quoteHide quote > I am attempting to solve a simple floating point math problem I think that dEndTime.Subtract(dStartTime).TotalHours is simpler.> 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. > -- Mike
How do I create new app with data access?
Concurrency error on update VB.NET Charting Solution HTML, CSS and JavaScript in a Gridview System.OutOfMemory exception error Excel interop. Choose version of Excel to launch is this possible? Pass a structure to a C++ dll Duplicated data - how to understand it please? Launch .NET application through notification or windows messaging Option |
|||||||||||||||||||||||