It is returning me a rounded number and I do not want ex number 1.99 and not 1.00 or 2.00

Asked

Viewed 39 times

0

Private Sub txtPricePerQty_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtPricePerQty.TextChanged
        Dim i As Double = 0
        i = CDbl(Val(txtQty.Text) * Val(txtPricePerQty.Text))
        i = Math.Round(i, 2)
        txtTotalAmount.Text = i
    End Sub

2 answers

0

Friend, I believe that what is causing the rounding is "Val()" because it is converting a string into an integer numeric value.

  • and what I have to do?

  • It is advisable to receive the values that are coming from the field in variables compatible with the type of data that you want to be calculated, as the own double, after that do the calculations based on the variables, debug before to see if the values are correct (debug.print).

  • but the variables are all as double

0

dim Qty as double = Val(txtQty.Text) dim Priceperqty as double = Val(txtPricePerQty.Text)

i = Cdbl(Qty * Priceperqty)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.