0

Ratio_Values.JPG Hi
I must sum calculated ratio values to the given amount of 2000.
Instead I get a sum not equal to 2000.
I know this has to do with the error in rounding.
How can I manage the rounding to sum to exactly 2000
Here is what I did so far:

**

 Private Sub btnLoad_Click(sender As System.Object, e As System.EventArgs) Handles btnLoad.Click
            If IsNumeric(txtAmt.Text) And dgv.Rows.Count > 0 Then
                     For i As Integer = 0 To dgv.Rows.Count - 1
                    dgv.Rows(i).Cells("CalculatedRatioVal").Value = Math.Round(CInt(dgv.Rows(i).Cells("rubVal").Value) * CInt(txtAmt.Text) / 2950, 2)
                 Next
            End If
    End Sub**

Thanks

Edited by gbhs_1

2
Contributors
1
Reply
9
Views
1 Year
Discussion Span
Last Post by rproffitt
0

Looking at it, should the per item calculation be like:
CalculatedRatioValue = int ( (2000 / RubValuetotal) * RubValue)

Sure you can change int() to what vb.net you like but this should be at most off by the number of line items. To explain why it might never be exactly 2000, well, you have to think about that.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.