Formatting label text

• Question

• I have two labels LABEL1 and LABEL2

LABEL1.text = "4.264544"

I want that LABEL2.text should be "4.2" ...  how can I make a label shows 2 digits after decimal

Any help will be appreciated

Friday, September 14, 2012 5:41 PM

• Hi Williams,

Use this code -

LABEL1.text = "4.264544"

Label2.Text = Math.Round(CDbl(Label1.Text), 2)

Now you have in Label2 is -

LABEL2.text = "4.26"

so, you can set the precision after decimal by changing 2,

thanks.

Pl. Mark/Proposed as Answer if found your solution Vote as Helpful if related to your topic. Always Motivate others by performing this Action.

• Edited by Friday, September 14, 2012 5:52 PM
• Proposed as answer by Friday, September 14, 2012 5:52 PM
• Marked as answer by Monday, September 24, 2012 8:00 AM
Friday, September 14, 2012 5:49 PM
• I have two labels LABEL1 and LABEL2

LABEL1.text = "4.264544"

I want that LABEL2.text should be "4.2" ...  how can I make a label shows 2 digits after decimal

Any help will be appreciated

Sid,

I'd do it a bit differently. If you're showing text then just set it like you want, but I suspect that what you're showing is based on some number coming from somewhere else. If I'm right on that, then use the overload of the .ToString to format it.

For instance:

Dim thisDbl as Double = 4.264544
Label1.Text = thisDbl.ToString("f2")

That's "fixed, show two decimal points.

I hope that helps. :)

• Proposed as answer by Saturday, September 15, 2012 6:11 AM
• Marked as answer by Monday, September 24, 2012 8:00 AM
Saturday, September 15, 2012 12:13 AM

All replies

• Hi Williams,

Use this code -

LABEL1.text = "4.264544"

Label2.Text = Math.Round(CDbl(Label1.Text), 2)

Now you have in Label2 is -

LABEL2.text = "4.26"

so, you can set the precision after decimal by changing 2,

thanks.

Pl. Mark/Proposed as Answer if found your solution Vote as Helpful if related to your topic. Always Motivate others by performing this Action.

• Edited by Friday, September 14, 2012 5:52 PM
• Proposed as answer by Friday, September 14, 2012 5:52 PM
• Marked as answer by Monday, September 24, 2012 8:00 AM
Friday, September 14, 2012 5:49 PM
• Dear Sid,

Pl. Mark/Proposed as Answer if found your solution Vote as Helpful if related to your topic. Always Motivate others by performing this Action.

Friday, September 14, 2012 6:11 PM
• I have two labels LABEL1 and LABEL2

LABEL1.text = "4.264544"

I want that LABEL2.text should be "4.2" ...  how can I make a label shows 2 digits after decimal

Any help will be appreciated

Sid,

I'd do it a bit differently. If you're showing text then just set it like you want, but I suspect that what you're showing is based on some number coming from somewhere else. If I'm right on that, then use the overload of the .ToString to format it.

For instance:

Dim thisDbl as Double = 4.264544
Label1.Text = thisDbl.ToString("f2")

That's "fixed, show two decimal points.

I hope that helps. :)