?
Solved

getting results of 2.3 to be displayed as 2.30

Posted on 2005-05-05
3
Medium Priority
?
300 Views
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.........
0
Comment
Question by:nwhan
  • 2
3 Comments
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 80 total points
ID: 13942455
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
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vafctFormat.asp

0
 
LVL 1

Author Comment

by:nwhan
ID: 13942911
hey man...

it works...save 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")
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 13943066
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

809 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