Need to convert $4.58 in the web text box to SQL Server.

  • Thread starter Thread starter culam
  • Start date Start date
C

culam

I have a webapp that allows user to enter amount in the
textbox then insert or update into SQL Server database as
decimal(13,4). I can update other fields OK, except the
currency field one.
Is there a function I can convert $4.58 from text box into
decimal.

Thanks,
Lam
 
one obvious way seems to be using substring in
conjunction with decimal.parse.

string txt = "$4.52";
txt = txt.Substring (1); // ignor the $ sign
try
{
decimal val = decimal.Parse(txt);
}
catch
{
// handle the error here
}

Alternatively, don't allow the user to type $ sign...
just put it before the text box.
 
Lam,
You can use
Decimal.Parse(txtBox.Text, System.Globalization.NumberStyles.Currency)
if you know you are always going to get a currency formatted string.
Ron Allen
 
Back
Top