hi,

i have 2 txtboxes n 1 label, a division if performed wid txtbox1 and txtbox2, then the result displayed in a label.

How can i format the label to display it to 2 dp. my current code is as follows:

Public Class Form1

         [INDENT][/INDENT]Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
                  Application.Exit()
         End Sub

         Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
                  Dim GPE As Decimal = txtGPE.Text.Length
                  Dim CT As Decimal = txtCT.Text
                  If GPE >= 0 And GPE <= 120 And CT >= 1 And CT <= 30 Then
                           lblGPA.Text = GPE / CT
                  Else
                           MessageBox.Show("Please Check Data again")
                  End If
         End Sub
End Class

Recommended Answers

All 3 Replies

1- Please when embedding code, use code tags to make yout code readable

Dim result As Decimal
        result = Decimal.Divide(Decimal.Parse(TextBox1.Text), Decimal.Parse(TextBox2.Text))
        result = FormatNumber(result, 2, TriState.False)
        Label1.Text = String.Format("the result = {0} ", result)
commented: Nice Code And Replies +8

will try it and let u knw

It works, friend :)
Mark it as solved :)

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.