Answered Formatting label text

  • Friday, September 14, 2012 5:41 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

All Replies

  • Friday, September 14, 2012 5:49 PM
     
     Answered

    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.

  • Friday, September 14, 2012 6:11 PM
     
     

    Dear Sid,

    what happened to your issue,

    were my last reply solved your problem?


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

  • Saturday, September 15, 2012 12:13 AM
     
     Answered

    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. :)


    Please call me Frank :)