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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.