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

Posted on 2007-11-26
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
Question by:mindserve
  • 3
  • 2
LVL 38

Expert Comment

ID: 20351358
Try this instead:

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

Expert Comment

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

TxtWholesalePrice.Text = CDbl(WholesalePrice).ToString("0.00")

Author Comment

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

Accepted Solution

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")

Author Comment

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

            Dim Price As Decimal = CDec(TxtWholesalePrice.Text)
            TxtWholesalePrice.Text = CDbl(Price).ToString("0.00")
        Catch ex As Exception
        End Try

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Exit a vb6 apps when a calling it apps closes 15 52
using web browser with BING 40 131
t-sql sp_addlinkedserver possible risks 3 93
What language/protocol is the Angular Chat? 2 84
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

856 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