Hi, sorry to ask this, I know it has been asked before but despite reading the answers I still dont get it. I am using visual studio 2008, vb.net.
I have a lable, label1. I want it to display the results of a calculation, a/b. The answer is a number typically 0.xxxxxxxxxx . I want the answer displayed to two decimal places in lable1. How do I achieve that please?

Thanks for all and any help.

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    Dim bigNumber As Decimal = 1234567.123456
    Console.WriteLine("F2: " & bigNumber.ToString("F2"))
    Console.WriteLine("N2: " & bigNumber.ToString("N2"))
    TextBox1.Text = bigNumber.ToString("F2")
End Sub

Results in:

F2: 1234567.12
N2: 1,234,567.12

So use F2 to not include a thousands separator, N2 will include it

Thank you for your reply, but the answer does not seem to be working for me.

In my code I have

dim a as double
dim b as double
'some calculation here wich typically results in 
'a/b being 0.xxxxxxx

label24.text =a/b

And I cannot get the text in label24 to format to 2 decimal places.
What am I doing wrong or have not grasped please. THank you again

This should work:

label24.Text = String.Format("{0:F2}", a/b)

you can try this hope it will work for you.

label24.text =Math.Round(a/b, 2)

or try this

label24.text = Format(a/b, "0.00")

try both hope it works with you

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.