Visual Studio 2005 vs Visual Studio 2008 #2

Are there any known issues with decimal rounding in VS 2008.  I have developed a timesheet app that calculates hours based on start and stop times.  It works fine when I use debugger in VS 2005 and a local host.  My boss uses VS 2008 to publish my app.  When he publishes it, my calculations are not rounding properly. 

Example:  Someone clocks in at 11:30pm and clocks out at 11:59pm,  in debug mode on my localhost, it rounds it to .5 hours.  When this code gets published, it rounds it to 0 hours.

 Thanks

0
jjkky
1/28/2009 4:51:17 PM
📁 asp.net.visual-studio-2008
📃 3408 articles.
⭐ 0 followers.

💬 8 Replies
👁️‍🗨️ 1371 Views

 Considering that both the VS 2005 and VS 2008 use the same version of the CLR, I would not expect this. Can you provide the code used to do the calculation?


Cheers,
       Kevin Jones


0
vcsjones
1/28/2009 5:48:20 PM

When you say 'debug mode' - do you mean 'compiled for debugging' or 'running under debugger' ? If application is stopped on a breakpoint or you are stepping through the code, clock is not running and you may see different numbers compared to a regular application run without debugging.


Thanks

------------------------------------------------------------

This posting is provided "AS IS" with no warranties, and confers no rights.
0
Mikhail
1/28/2009 5:57:31 PM

It's an awful lot of code but here it is and thanks for reviewing:

 ========================================

vsubHTot1 = 0

vsubHTot2 = 0

vsubHTot3 = 0

vsubMTot1 = 0

vsubMTot2 = 0

vsubMTot3 = 0

Dim dFirstShiftTot As Decimal = 0

Dim dSecondShiftTot As Decimal = 0

Dim dThirdShiftTot As Decimal = 0

Dim dTotalShift As Decimal = 0

Dim ttot As Decimal = 0

Dim ctot As Decimal = 0

Dim vfTot As Decimal = 0

Dim vsTot As Decimal = 0

Dim vtTot As Decimal = 0

Dim vtotmins As Integer = 0

Dim vtothours As Integer = 0

Dim rtotmins As Integer = 0

Dim rtothours As Integer = 0

 

'========= Calculate First Time In and First Time Out

If (dIn1 >= rbFshift) And (dIn1 <= reFShift) Then

If dOut1 >= rbFshift And dOut1 <= reFShift Then

ctot = CalcTimeDiff(dIn1, dOut1)

dFirstShiftTot = dFirstShiftTot + ctot

ElseIf dOut1 >= rbFshift Then

reFShift = tdate & " 4:00:00 PM"

vsubHTot1 = System.Math.Round(DateDiff("s", dIn1, reFShift) \ (60 * 60), 2, MidpointRounding.AwayFromZero)vsubMTot1 = System.Math.Round((DateDiff("s", dIn1, reFShift) Mod (60 * 60)) \ 60, 2, MidpointRounding.AwayFromZero)

vtothours = vtothours + vsubHTot1

vtotmins = vtotmins + vsubMTot1

vtotmins = RoundMinutes(vtotmins)

' Modified by JJK 6/11/2008

If vtotmins > 52 Then

vtotmins = 0

vsubMTot1 = 0

vtothours = vtothours + 1

vsubHTot1 = vsubHTot1 + 1

End If

' End Modification

xTotal1 = System.Math.Round(vsubHTot1 + (vtotmins / 60), 2, MidpointRounding.AwayFromZero)

dFirstShiftTot = dFirstShiftTot + xTotal1

vsTot = AddSecondShift(dOut1, dSecondShiftTot, rbSShift, vsTot)

dSecondShiftTot = vsTot

reFShift = tdate & " 3:59:59 PM"

End If

End If

If (dIn1 >= rbSShift) And (dIn1 <= reSShift) Then

If dOut1 >= rbSShift And dOut1 <= reSShift Then

ctot = CalcTimeDiff(dIn1, dOut1)

dSecondShiftTot = dSecondShiftTot + ctot

ElseIf dOut1 >= rbSShift Then

vsubHTot2 = System.Math.Round(DateDiff("s", dIn1, reSShift) \ (60 * 60), 2, MidpointRounding.AwayFromZero)vsubMTot2 = System.Math.Round((DateDiff("s", dIn1, reSShift) Mod (60 * 60)) \ 60, 2, MidpointRounding.AwayFromZero)

vtothours = vtothours + vsubHTot2

vtotmins = vtotmins + vsubMTot2

vtotmins = RoundMinutes(vtotmins)

' Modified by JJK 6/11/2008

If vtotmins > 52 Then

vtotmins = 0

vsubMTot2 = 0

vtothours = vtothours + 1

vsubHTot2 = vsubHTot2 + 1

End If

' End Modification

xTotal2 = System.Math.Round(vsubHTot2 + (vtotmins / 60), 2, MidpointRounding.AwayFromZero)

dSecondShiftTot = dSecondShiftTot + xTotal2

vtTot = AddThirdShift(dOut1, dThirdShiftTot, rbTShift, vtTot)

dThirdShiftTot = vtTot

End If

End If

If (dIn1 >= rbTShift) And (dIn1 <= reTShift) Then

If dOut1 >= rbTShift And dOut1 <= reTShift Then

ctot = CalcTimeDiff(dIn1, dOut1)

dThirdShiftTot = dThirdShiftTot + ctot

ElseIf dOut1 >= rbTShift Then

reTShift = tdate & " 8:00:00 AM"

vsubHTot3 = System.Math.Round(DateDiff("s", dIn1, reTShift) \ (60 * 60), 2, MidpointRounding.AwayFromZero)vsubMTot3 = System.Math.Round((DateDiff("s", dIn1, reTShift) Mod (60 * 60)) \ 60, 2, MidpointRounding.AwayFromZero)

vtothours = vtothours + vsubHTot3

vtotmins = vtotmins + vsubMTot3

vtotmins = RoundMinutes(vtotmins)

' Modified by JJK 6/11/2008

If vtotmins > 52 Then

vtotmins = 0

vsubMTot3 = 0

vtothours = vtothours + 1

vsubHTot3 = vsubHTot3 + 1

End If

' End Modification

xTotal3 = System.Math.Round(vsubHTot3 + (vtotmins / 60), 2, MidpointRounding.AwayFromZero)

dThirdShiftTot = dThirdShiftTot + xTotal3

vfTot = AddFirstShift(dOut1, dFirstShiftTot, rbFshift, vfTot)

' Modified by JJK on 2/6/2008 =================================

dFirstShiftTot = vfTot

If vfTot > 8 Then

dSecondShiftTot = dSecondShiftTot + (vfTot - 8)

dFirstShiftTot = 8

End If

'End Modification =================================

reTShift = tdate & " 7:59:59 AM"

End If

End If

'========= Calculate Second Time In and Second Time Out

If (dIn2 >= rbFshift) And (dIn2 <= reFShift) Then

If dOut2 >= rbFshift And dOut2 <= reFShift Then

ctot = CalcTimeDiff(dIn2, dOut2)

dFirstShiftTot = dFirstShiftTot + ctot

ElseIf dOut2 >= rbFshift Then

reFShift = tdate & " 4:00:00 PM"

vsubHTot1 = System.Math.Round(DateDiff("s", dIn2, reFShift) \ (60 * 60), 2, MidpointRounding.AwayFromZero)vsubMTot1 = System.Math.Round((DateDiff("s", dIn2, reFShift) Mod (60 * 60)) \ 60, 2, MidpointRounding.AwayFromZero)

vtothours = vtothours + vsubHTot1

vtotmins = vtotmins + vsubMTot1

vtotmins = RoundMinutes(vtotmins)

' Modified by JJK 6/11/2008

If vtotmins > 52 Then

vtotmins = 0

vsubMTot1 = 0

vtothours = vtothours + 1

vsubHTot1 = vsubHTot1 + 1

End If

' End Modification

xTotal1 = System.Math.Round(vsubHTot1 + (vtotmins / 60), 2, MidpointRounding.AwayFromZero)

dFirstShiftTot = dFirstShiftTot + xTotal1

vsTot = AddSecondShift(dOut2, dSecondShiftTot, rbSShift, vsTot)

dSecondShiftTot = vsTot

reFShift = tdate & " 3:59:59 PM"

End If

End If

If (dIn2 >= rbSShift) And (dIn2 <= reSShift) Then

If dOut2 >= rbSShift And dOut2 <= reSShift Then

ctot = CalcTimeDiff(dIn2, dOut2)

dSecondShiftTot = dSecondShiftTot + ctot

ElseIf dOut2 >= rbSShift Then

vsubHTot2 = System.Math.Round(DateDiff("s", dIn2, reSShift) \ (60 * 60), 2, MidpointRounding.AwayFromZero)vsubMTot2 = System.Math.Round((DateDiff("s", dIn2, reSShift) Mod (60 * 60)) \ 60, 2, MidpointRounding.AwayFromZero)

vtothours = vtothours + vsubHTot2

vtotmins = vtotmins + vsubMTot2

vtotmins = RoundMinutes(vtotmins)

' Modified by JJK 6/11/2008

If vtotmins > 52 Then

vtotmins = 0

vsubMTot2 = 0

vtothours = vtothours + 1

vsubHTot2 = vsubHTot2 + 1

End If

' End Modification

xTotal2 = System.Math.Round(vsubHTot2 + (vtotmins / 60), 2, MidpointRounding.AwayFromZero)

dSecondShiftTot = dSecondShiftTot + xTotal2

vtTot = AddThirdShift(dOut2, dThirdShiftTot, rbTShift, vtTot)

dThirdShiftTot = vtTot

End If

End If

If (dIn2 >= rbTShift) And (dIn2 <= reTShift) Then

If dOut2 >= rbTShift And dOut2 <= reTShift Then

ctot = CalcTimeDiff(dIn2, dOut2)

dThirdShiftTot = dThirdShiftTot + ctot

ElseIf dOut2 >= rbTShift Then

reTShift = tdate & " 8:00:00 AM"

vsubHTot3 = System.Math.Round(DateDiff("s", dIn2, reTShift) \ (60 * 60), 2, MidpointRounding.AwayFromZero)vsubMTot3 = System.Math.Round((DateDiff("s", dIn2, reTShift) Mod (60 * 60)) \ 60, 2, MidpointRounding.AwayFromZero)

vtothours = vtothours + vsubHTot3

vtotmins = vtotmins + vsubMTot3

vtotmins = RoundMinutes(vtotmins)

' Modified by JJK 6/11/2008

If vtotmins > 52 Then

vtotmins = 0

vsubMTot3 = 0

vtothours = vtothours + 1

vsubHTot3 = vsubHTot3 + 1

End If

' End Modification

xTotal3 = System.Math.Round(vsubHTot3 + (vtotmins / 60), 2, MidpointRounding.AwayFromZero)

dThirdShiftTot = dThirdShiftTot + xTotal3

vfTot = AddFirstShift(dOut2, dFirstShiftTot, rbFshift, vfTot)

dFirstShiftTot = vfTot

reTShift = tdate & " 7:59:59 AM"

End If

End If

'========= Calculate Third Time In and Third Time Out

If (dIn3 >= rbFshift) And (dIn3 <= reFShift) Then

If dOut3 >= rbFshift And dOut3 <= reFShift Then

ctot = CalcTimeDiff(dIn3, dOut3)

dFirstShiftTot = dFirstShiftTot + ctot

ElseIf dOut3 >= rbFshift Then

reFShift = tdate & " 4:00:00 PM"

vsubHTot1 = System.Math.Round(DateDiff("s", dIn3, reFShift) \ (60 * 60), 2, MidpointRounding.AwayFromZero)vsubMTot1 = System.Math.Round((DateDiff("s", dIn3, reFShift) Mod (60 * 60)) \ 60, 2, MidpointRounding.AwayFromZero)

vtothours = vtothours + vsubHTot1

vtotmins = vtotmins + vsubMTot1

vtotmins = RoundMinutes(vtotmins)

' Modified by JJK 6/11/2008

If vtotmins > 52 Then

vtotmins = 0

vsubMTot1 = 0

vtothours = vtothours + 1

vsubHTot1 = vsubHTot1 + 1

End If

' End Modification

xTotal1 = System.Math.Round(vsubHTot1 + (vtotmins / 60), 2, MidpointRounding.AwayFromZero)

dFirstShiftTot = dFirstShiftTot + xTotal1

vsTot = AddSecondShift(dOut3, dSecondShiftTot, rbSShift, vsTot)

dSecondShiftTot = vsTot

reFShift = tdate & " 3:59:59 PM"

End If

End If

If (dIn3 >= rbSShift) And (dIn3 <= reSShift) Then

If dOut3 >= rbSShift And dOut3 <= reSShift Then

ctot = CalcTimeDiff(dIn3, dOut3)

dSecondShiftTot = dSecondShiftTot + ctot

ElseIf dOut3 >= rbSShift Then

vsubHTot2 = System.Math.Round(DateDiff("s", dIn3, reSShift) \ (60 * 60), 2, MidpointRounding.AwayFromZero)vsubMTot2 = System.Math.Round((DateDiff("s", dIn3, reSShift) Mod (60 * 60)) \ 60, 2, MidpointRounding.AwayFromZero)

vtothours = vtothours + vsubHTot2

vtotmins = vtotmins + vsubMTot2

vtotmins = RoundMinutes(vtotmins)

' Modified by JJK 6/11/2008

If vtotmins > 52 Then

vtotmins = 0

vsubMTot2 = 0

vtothours = vtothours + 1

vsubHTot2 = vsubHTot2 + 1

End If

' End Modification

xTotal2 = System.Math.Round(vsubHTot2 + (vtotmins / 60), 2, MidpointRounding.AwayFromZero)

dSecondShiftTot = dSecondShiftTot + xTotal2

vtTot = AddThirdShift(dOut3, dThirdShiftTot, rbTShift, vtTot)

dThirdShiftTot = vtTot

End If

End If

If (dIn3 >= rbTShift) And (dIn3 <= reTShift) Then

If dOut3 >= rbTShift And dOut3 <= reTShift Then

ctot = CalcTimeDiff(dIn3, dOut3)

dThirdShiftTot = dThirdShiftTot + ctot

ElseIf dOut3 >= rbTShift Then

reTShift = tdate & " 8:00:00 AM"

vsubHTot3 = System.Math.Round(DateDiff("s", dIn3, reTShift) \ (60 * 60), 2, MidpointRounding.AwayFromZero)vsubMTot3 = System.Math.Round((DateDiff("s", dIn3, reTShift) Mod (60 * 60)) \ 60, 2, MidpointRounding.AwayFromZero)

vtothours = vtothours + vsubHTot3

vtotmins = vtotmins + vsubMTot3

vtotmins = RoundMinutes(vtotmins)

' Modified by JJK 6/11/2008

If vtotmins > 52 Then

vtotmins = 0

vsubMTot3 = 0

vtothours = vtothours + 1

vsubHTot3 = vsubHTot3 + 1

End If

' End Modification

xTotal3 = System.Math.Round(vsubHTot3 + (vtotmins / 60), 2, MidpointRounding.AwayFromZero)

dThirdShiftTot = dThirdShiftTot + xTotal3

vfTot = AddFirstShift(dOut3, dFirstShiftTot, rbFshift, vfTot)

dFirstShiftTot = vfTot

reTShift = tdate & " 7:59:59 AM"

End If

End If

Dim vFShiftTot As Decimal = System.Math.Round(dFirstShiftTot, 2, MidpointRounding.AwayFromZero)

Dim vSShiftTot As Decimal = System.Math.Round(dSecondShiftTot, 2, MidpointRounding.AwayFromZero)

Dim vTShiftTot As Decimal = System.Math.Round(dThirdShiftTot, 2, MidpointRounding.AwayFromZero)

Dim vTotalShift As Decimal = System.Math.Round(vFShiftTot + vSShiftTot + vTShiftTot, 2, MidpointRounding.AwayFromZero)

'Temp Comment - txtTotal.Text = vTotalShift

vReturn = vFShiftTot & "," & vSShiftTot & "," & vTShiftTot & "," & vTotalShift & "," & vtothours & "," & vtotmins

Return vReturn

End Function

Public Shared Function AddFirstShift(ByVal vIn, ByVal vdFirstShiftTot, ByVal vrbFshift, ByVal vftot)

Dim htot As Decimal = 0

Dim mtot As Decimal = 0

Dim ftot As Decimal = 0

Dim rFirstShiftTot As String

htot = System.Math.Round(DateDiff("s", vrbFshift, vIn) \ (60 * 60), 2, MidpointRounding.AwayFromZero)mtot = System.Math.Round((DateDiff("s", vrbFshift, vIn) Mod (60 * 60)) \ 60, 2, MidpointRounding.AwayFromZero)

ftot = RoundMinutes(mtot)

If ftot > 52 Then

mtot = 0

htot = htot + 1

Else

mtot = ftot

End If

vftot = System.Math.Round(vftot + htot + (mtot / 60), 2, MidpointRounding.AwayFromZero)

vdFirstShiftTot = vdFirstShiftTot + vftot

rFirstShiftTot = vdFirstShiftTot

Return rFirstShiftTot

End Function

Public Shared Function AddSecondShift(ByVal vIn, ByVal vdSecondShiftTot, ByVal vrbSshift, ByVal vstot)

Dim htot As Decimal = 0

Dim mtot As Decimal = 0

Dim ftot As Decimal = 0

Dim rSecondShiftTot As String

htot = System.Math.Round(DateDiff("s", vrbSshift, vIn) \ (60 * 60), 2, MidpointRounding.AwayFromZero)mtot = System.Math.Round((DateDiff("s", vrbSshift, vIn) Mod (60 * 60)) \ 60, 2, MidpointRounding.AwayFromZero)

ftot = RoundMinutes(mtot)

If ftot > 52 Then

mtot = 0

htot = htot + 1

Else

mtot = ftot

End If

vstot = System.Math.Round(vstot + htot + (mtot / 60), 2, MidpointRounding.AwayFromZero)

vdSecondShiftTot = vdSecondShiftTot + vstot

rSecondShiftTot = vdSecondShiftTot

Return rSecondShiftTot

End Function

Public Shared Function AddThirdShift(ByVal vIn, ByVal vdThirdShiftTot, ByVal vrbTshift, ByVal vttot)

Dim htot As Decimal = 0

Dim mtot As Decimal = 0

Dim ftot As Decimal = 0

Dim rThirdShiftTot As String

htot = System.Math.Round(DateDiff("s", vrbTshift, vIn) \ (60 * 60), 2, MidpointRounding.AwayFromZero)mtot = System.Math.Round((DateDiff("s", vrbTshift, vIn) Mod (60 * 60)) \ 60, 2, MidpointRounding.AwayFromZero)

ftot = RoundMinutes(mtot)

If ftot > 52 Then

mtot = 0

htot = htot + 1

Else

mtot = ftot

End If

vttot = System.Math.Round(vttot + htot + (mtot / 60), 2, MidpointRounding.AwayFromZero)

vdThirdShiftTot = vdThirdShiftTot + vttot

rThirdShiftTot = vdThirdShiftTot

Return rThirdShiftTot

End Function

Public Shared Function CalcTimeDiff(ByVal vIn, ByVal vOut)

Dim ctot = 0

Dim ftot As Decimal = 0

Dim rCalcTot As String

Dim htot = System.Math.Round(DateDiff("s", vIn, vOut) \ (60 * 60), 2, MidpointRounding.AwayFromZero)Dim mtot = System.Math.Round((DateDiff("s", vIn, vOut) Mod (60 * 60)) \ 60, 2, MidpointRounding.AwayFromZero)

ftot = RoundMinutes(mtot)

If ftot > 52 Then

mtot = 0

htot = htot + 1

Else

mtot = ftot

End If

ctot = System.Math.Round(htot + (mtot / 60), 2)

rCalcTot = ctot

Return rCalcTot

End Function

Public Shared Function RoundMinutes(ByVal vMin)

Dim cMin = 0

If vMin >= 0 And vMin <= 7 Then

cMin = 0

Else

If vMin >= 8 And vMin <= 22 Then

cMin = 15

Else

If vMin >= 23 And vMin <= 37 Then

cMin = 30

Else

If vMin >= 38 And vMin <= 52 Then

cMin = 45

Else

cMin = vMin

End If

End If

End If

End If

Return cMin

End Function

0
jjkky
1/28/2009 6:08:27 PM

Sorry for not being clear, I meant aspx file Smile


Thanks

------------------------------------------------------------

This posting is provided "AS IS" with no warranties, and confers no rights.
0
Mikhail
1/28/2009 6:16:45 PM

Too much proprietary info to send the whole file.  Thanks anyway.

 

0
jjkky
1/28/2009 6:26:37 PM

How's about just top-level page directive?


Thanks

------------------------------------------------------------

This posting is provided "AS IS" with no warranties, and confers no rights.
0
Mikhail
1/28/2009 8:32:50 PM

I'm somewhat new to aspx.  Do you mean this?

<%@ Page Language="VB" MasterPageFile="~/TimeMasterPage.master" MaintainScrollPositionOnPostback = "true" CodeFile="Timesheet.aspx.vb" Inherits="Timesheet" title="Timesheet Entry Form" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server" >

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >

0
jjkky
1/28/2009 9:09:12 PM

I've determined it not the VS version that is the problem but I still don't have it resolved.  Could it be related to the fact that he is publishing it from a PC running Windows Vista and I am developing it on Windows XP?

Thanks!

0
jjkky
1/29/2009 5:00:48 PM
Reply: