Break it up bit by bit. Find out which line is causing the incorrect rounding, and correct it from that point. I would do it this way:
strquery = "select Rate from ORTT where currency = '" & test & "' order by RateDate desc"
rs = oGFun.DoQuery(strquery)
Insert a breakpoint after these two lines, and see if it got rounded here. I would rewrite the next couple of lines:
Dim test1 As Integer = 0
Integer.TryParse(rs.Fields.Item("Rate").value, test1)
By trying the parse first, you make sure that it's possible to change the value to an integer, and not just assume that you can. You can then put a breakpoint after these lines and see if test1 now has a correct value here. Finally...
oDBDSHeader.SetValue("U_price", 0, rs.Fields.Item("Rate").Value)
Stick a breakpoint immediately after the line above. If the SetValue method for some reason is the line that's causing the incorrect rounding, then you'll need to handle the value yourself with just a basic bit of logic. Something like the following:
Private Function roundProperly(ByVal dInput As Decimal) As Integer
Try
Dim sInput As String = dInput.ToString
Dim iReturn As Integer = 0
Integer.TryParse(sInput.Substring(0, sInput.IndexOf(".")), iReturn)
'If there is no decimal place, just return the input value
If sInput.IndexOf(".") = -1 Then Return dInput
'If there is a decimal place, then check the value of the digit after the decimal place
Dim sDigitAfter As String = sInput.Substring(sInput.IndexOf(".") + 1, 1)
Dim iDigitAfter As Integer = 0
Integer.TryParse(sDigitAfter, iDigitAfter)
If iDigitAfter < 5 Then
Return iReturn
Else
Return iReturn + 1
End If
Catch ex As Exception
MsgBox("Error: " & ex.Message)
Return Nothing
End Try
End Function
Note that I normally don't break down my code into this many lines, I usually have more of these functions merged into each other on the same line. But I broke it down as far as I could to give you the most possible breakpoints to investigate issues with the function.
If you throw 1.4 into roundProperly, you should get "1". If you throw in 1.5, you should get back 2. Let me know whether or not these ideas help resolve your issue.