Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format a text box as currency 1

Status
Not open for further replies.

Saturn57

Programmer
Aug 30, 2007
275
CA
I cannot figure out the code to have a text box show the input as currency. Any help is appreciated. Im sure this is an easy one.
 
wouldn't something like this work
textbox.Text = a_number.ToString("c");

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
That did not work. Here is what Im trying to convert to a curency format:

sumcdnpriceTB.Text = (Convert.ToString(cmd.Parameters["@cdnpricesum"].Value.ToString()));
 
I wouldn't have my ado objects interacting directly with my GUI.
you are converting the value to a string and then calling ToString() this is redundant and will not allow you to format the value.

current is a numeric concept. To format a value as currency the value must be a numeric type. int, long, decimal, float, etc.

Code:
var result = cmd.Parameters["@cdnpricesum"].Value;
var currency = (float)result; //or other appropriate type
sumcdnpriceTB.Text = currency.ToString("c");

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Sorry Im getting this error now

Error 1 The type or namespace name 'var' could not be found (are you missing a using directive or an assembly reference?) E:\VisualStudioProjects\EstimatorC\EstimatorC\EstimateReview.cs 63 29 EstimatorC
 
c#3.0 syntax. if you are using VS2005 you need to define the type explicitly.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top