Solved

VB 2005 parse string and format with 2 trailing zero's

Posted on 2007-11-26
5
1,573 Views
Last Modified: 2013-11-25
This code produces and error in vb 2005 .net 3 framework. How do I get the textbox which is an Access database backend and text datatype to show 45.00 rather than 45  I don't need the Currency symbol.


Private Sub TxtWholesalePrice_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles TxtWholesalePrice.Validated
        Dim WholesalePrice As Decimal
        TxtWholesalePrice.Text = Decimal.Parse(WholesalePrice, 2).ToString("f2")
       
    End Sub
0
Comment
Question by:mindserve
  • 3
  • 2
5 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 20351358
Try this instead:

TxtWholesalePrice.Text = Decimal.Parse(WholesalePrice, 2).ToString("0.00")
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 20351468
Actually the parse is not being called correctly.  Just convert to floating point and format:

TxtWholesalePrice.Text = CDbl(WholesalePrice).ToString("0.00")
0
 
LVL 1

Author Comment

by:mindserve
ID: 20351838
What that gives me is 0.00 when I enter 45 , but not 45.00..??? any other ideas?
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 125 total points
ID: 20352918
That extra variable never gets populated.  We need to take the value from the textbox, convert it and format it.

TxtWholesalePrice.Text = CDbl(TxtWholesalePrice).ToString("0.00")
0
 
LVL 1

Author Comment

by:mindserve
ID: 20353032
This worked, but I had to declare price as decimal...


Try
            Dim Price As Decimal = CDec(TxtWholesalePrice.Text)
            TxtWholesalePrice.Text = CDbl(Price).ToString("0.00")
        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.ToString)
        End Try
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

914 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

14 Experts available now in Live!

Get 1:1 Help Now