This is my code and I want the output which is txtA.Text
and txtB.Text
to be in two decimal places.
Public Class Form1
Private Sub btncalc_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btncalc.Click
txtA.Text = Val(txtD.Text) / Val(txtC.Text) * Val(txtF.Text) / Val(txtE.Text)
txtB.Text = Val(txtA.Text) * 1000 / Val(txtG.Text)
End Sub
End Class
Rounding to a certain number of decimal places4.737 rounded to 2 decimal places would be 4.74 (because it would be closer to 4.74). 4.735 is halfway between 4.73 and 4.74, so it is rounded up: 4.735 rounded to 2 decimal places is 4.74.
74, which is 2 decimal places.
Click the Table Tools' Layout tab, select Data and then click Formula. Click the Number Format menu and select 0.00 for two decimals.
For formatting options, see this
Dim v1 as Double = Val(txtD.Text) / Val(txtC.Text) *
Val(txtF.Text) / Val(txtE.Text)
txtA.text = v1.ToString("N2");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With