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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Values in a textbox

Status
Not open for further replies.

ac11nyc

Programmer
Oct 1, 2003
94
US
Can someone tell me how i can make a value in a textbox be the current value plus a decimal and two zeros ALWAYS. Even if they put 4.5, i want to be 4.50 and if they just put 4, i want it to be 4.00. Any help will be greatly appreciated. Thankx Cube
 
I would say you'd want to use client side javascript for this...other wise there is a formatcurrenct function within vb that you could use...if it's on a postback...

FormatNumber(number,decimalplaces)

dlc
 
Add first to the for TextBox2 control.
Then Add the following event TextBox2 . This is going to fire when the text is changed.
Same thing you can do with javascript.

private void TextBox2_OnChange(object sender, System.EventArgs e)
{
string newval;
string sval = TextBox2.Text;
string[] lsval = sval.Split(char.Parse("."));
if(lsval.Length == 1)
newval = lsval[0] + ".00";
else
newval = lsval[0] + "." + lsval[1].PadRight(2, char.Parse("0"));
TextBox2.Text = newval;

}

Success
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top