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 |
![]() |
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 |
![]() |
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 = 0Dim dThirdShiftTot As Decimal = 0 Dim dTotalShift As Decimal = 0Dim ttot As Decimal = 0 Dim ctot As Decimal = 0Dim vfTot As Decimal = 0 Dim vsTot As Decimal = 0Dim vtTot As Decimal = 0 Dim vtotmins As Integer = 0Dim vtothours As Integer = 0 Dim rtotmins As Integer = 0Dim 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 ThenreFShift = 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 Thenvtotmins = 0
vsubMTot1 = 0
vtothours = vtothours + 1
vsubHTot1 = vsubHTot1 + 1
End If ' End ModificationxTotal1 = 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 Thenctot = CalcTimeDiff(dIn1, dOut1)
dSecondShiftTot = dSecondShiftTot + ctot
ElseIf dOut1 >= rbSShift ThenvsubHTot2 = 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 Thenvtotmins = 0
vsubMTot2 = 0
vtothours = vtothours + 1
vsubHTot2 = vsubHTot2 + 1
End If ' End ModificationxTotal2 = 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 Thenctot = CalcTimeDiff(dIn1, dOut1)
dThirdShiftTot = dThirdShiftTot + ctot
ElseIf dOut1 >= rbTShift ThenreTShift = 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 Thenvtotmins = 0
vsubMTot3 = 0
vtothours = vtothours + 1
vsubHTot3 = vsubHTot3 + 1
End If ' End ModificationxTotal3 = 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 ThendSecondShiftTot = 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 Thenctot = CalcTimeDiff(dIn2, dOut2)
dFirstShiftTot = dFirstShiftTot + ctot
ElseIf dOut2 >= rbFshift ThenreFShift = 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 Thenvtotmins = 0
vsubMTot1 = 0
vtothours = vtothours + 1
vsubHTot1 = vsubHTot1 + 1
End If ' End ModificationxTotal1 = 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 Thenctot = CalcTimeDiff(dIn2, dOut2)
dSecondShiftTot = dSecondShiftTot + ctot
ElseIf dOut2 >= rbSShift ThenvsubHTot2 = 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 Thenvtotmins = 0
vsubMTot2 = 0
vtothours = vtothours + 1
vsubHTot2 = vsubHTot2 + 1
End If ' End ModificationxTotal2 = 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 Thenctot = CalcTimeDiff(dIn2, dOut2)
dThirdShiftTot = dThirdShiftTot + ctot
ElseIf dOut2 >= rbTShift ThenreTShift = 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 Thenvtotmins = 0
vsubMTot3 = 0
vtothours = vtothours + 1
vsubHTot3 = vsubHTot3 + 1
End If ' End ModificationxTotal3 = 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 Thenctot = CalcTimeDiff(dIn3, dOut3)
dFirstShiftTot = dFirstShiftTot + ctot
ElseIf dOut3 >= rbFshift ThenreFShift = 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 Thenvtotmins = 0
vsubMTot1 = 0
vtothours = vtothours + 1
vsubHTot1 = vsubHTot1 + 1
End If ' End ModificationxTotal1 = 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 Thenctot = CalcTimeDiff(dIn3, dOut3)
dSecondShiftTot = dSecondShiftTot + ctot
ElseIf dOut3 >= rbSShift ThenvsubHTot2 = 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 Thenvtotmins = 0
vsubMTot2 = 0
vtothours = vtothours + 1
vsubHTot2 = vsubHTot2 + 1
End If ' End ModificationxTotal2 = 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 Thenctot = CalcTimeDiff(dIn3, dOut3)
dThirdShiftTot = dThirdShiftTot + ctot
ElseIf dOut3 >= rbTShift ThenreTShift = 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 Thenvtotmins = 0
vsubMTot3 = 0
vtothours = vtothours + 1
vsubHTot3 = vsubHTot3 + 1
End If ' End ModificationxTotal3 = 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 IfDim 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 = vTotalShiftvReturn = vFShiftTot & "," & vSShiftTot & "," & vTShiftTot & "," & vTotalShift & "," & vtothours & "," & vtotmins Return vReturn End FunctionPublic Shared Function AddFirstShift(ByVal vIn, ByVal vdFirstShiftTot, ByVal vrbFshift, ByVal vftot) Dim htot As Decimal = 0Dim mtot As Decimal = 0 Dim ftot As Decimal = 0 Dim rFirstShiftTot As Stringhtot = 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 Thenmtot = 0
htot = htot + 1
Elsemtot = ftot
End Ifvftot = System.Math.Round(vftot + htot + (mtot / 60), 2, MidpointRounding.AwayFromZero)
vdFirstShiftTot = vdFirstShiftTot + vftot
rFirstShiftTot = vdFirstShiftTot
Return rFirstShiftTot End FunctionPublic Shared Function AddSecondShift(ByVal vIn, ByVal vdSecondShiftTot, ByVal vrbSshift, ByVal vstot) Dim htot As Decimal = 0Dim mtot As Decimal = 0 Dim ftot As Decimal = 0 Dim rSecondShiftTot As Stringhtot = 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 Thenmtot = 0
htot = htot + 1
Elsemtot = ftot
End Ifvstot = System.Math.Round(vstot + htot + (mtot / 60), 2, MidpointRounding.AwayFromZero)
vdSecondShiftTot = vdSecondShiftTot + vstot
rSecondShiftTot = vdSecondShiftTot
Return rSecondShiftTot End FunctionPublic Shared Function AddThirdShift(ByVal vIn, ByVal vdThirdShiftTot, ByVal vrbTshift, ByVal vttot) Dim htot As Decimal = 0Dim mtot As Decimal = 0 Dim ftot As Decimal = 0 Dim rThirdShiftTot As Stringhtot = 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 Thenmtot = 0
htot = htot + 1
Elsemtot = ftot
End Ifvttot = System.Math.Round(vttot + htot + (mtot / 60), 2, MidpointRounding.AwayFromZero)
vdThirdShiftTot = vdThirdShiftTot + vttot
rThirdShiftTot = vdThirdShiftTot
Return rThirdShiftTot End FunctionPublic Shared Function CalcTimeDiff(ByVal vIn, ByVal vOut) Dim ctot = 0Dim ftot As Decimal = 0 Dim rCalcTot As StringDim 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 Thenmtot = 0
htot = htot + 1
Elsemtot = ftot
End Ifctot = System.Math.Round(htot + (mtot / 60), 2)
rCalcTot = ctot
Return rCalcTot End FunctionPublic Shared Function RoundMinutes(ByVal vMin) Dim cMin = 0 If vMin >= 0 And vMin <= 7 ThencMin = 0
Else If vMin >= 8 And vMin <= 22 ThencMin = 15
Else If vMin >= 23 And vMin <= 37 ThencMin = 30
Else If vMin >= 38 And vMin <= 52 ThencMin = 45
ElsecMin = vMin
End If End If End If End IfReturn cMin End Function
![]() |
0 |
![]() |
Sorry for not being clear, I meant aspx file
Thanks
------------------------------------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
![]() |
0 |
![]() |
Too much proprietary info to send the whole file. Thanks anyway.
![]() |
0 |
![]() |
How's about just top-level page directive?
Thanks
------------------------------------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
![]() |
0 |
![]() |
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 |
![]() |
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 |
![]() |