How to check decimal places from TextBox input?

  • Thread starter pedestrian via DotNetMonster.com
  • Start date
P

pedestrian via DotNetMonster.com

Says I have a TextBox which accept money values. (Assume I cast the input
into Decimal data type), how to check whether user is enter 2 decimal places
(valid)
or more than 2 decimal places (invalid input for money values)?

Thanks for replying...
 
C

Claes Bergefall

Find the decimal character and then just count the characters that comes
after. Something like this:

int index =
textBox.Text.IndexOf(NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator);
int count = textBox.Text.SubString(index + 1).Length;

/claes
 
P

pedestrian via DotNetMonster.com

Thanks for valuable answer, Claes...
I shall try it....

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top