getting results of 2.3 to be displayed as 2.30

Posted on 2005-05-05
Last Modified: 2010-04-23
i have 3 textboxes and 1button :

-2input textboxes (txtfirstnum + txtsecondnum)
-1output textbox (txttotal)
-1button (btnadd)

example : 2.1 + 3.5 = 5.6

*instead of displaying 5.6 , i would like to display 5.60 (2decimal points)

how to put the codes ?
help guys.........
Question by:nwhan
    LVL 62

    Accepted Solution

    Here is one way to do it.

        Private Sub btnadd_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles btnadd.Click

            Dim firstNum As Single
            Dim secondNum As Single
            Dim total As Single

            firstNum = CSng(txtfirstnum.Text.ToString)
            secondNum = CSng(txtsecondnum.Text.ToString)
            total = firstNum + secondNum
            txttotal.Text = Format(total, "###,###,##0.00")

        End Sub

    Go to this web site to read upp on the Format Function

    LVL 1

    Author Comment

    hey man...

    it my day...hehe...
    thanks a million...
    get the way how it works..but not really the logics..mind to explain ?
    juz briefly... for the last line :

     txttotal.Text = Format(total, "###,###,##0.00")
    LVL 62

    Expert Comment

    by:Fernando Soto
    txttotal.Text = Format(total, "###,###,##0.00")
    The Format function takes as its first parameter any valid expression, and formats it to a string according to the second parameter which is a string format required.  Look at the web site I posted in the first question and at the bottom of the page under “See Also” you will find links to other pages explaining how to form the format sting.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now