Click here to Skip to main content
15,911,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii,

my requirement is .. i dont want to allow any floating values or decimal places value ... only without decimal ... if user enters i want to throw an exception
Posted
Comments
[no name] 5-Sep-13 7:01am    
Okay so go ahead and do that. You have permission to proceed.
Torakami 5-Sep-13 7:09am    
you havent updated any answer for this
[no name] 5-Sep-13 7:30am    
Why should I? There is no question here to answer.
Torakami 5-Sep-13 8:00am    
I think you can c .. some one has already give me answer for that .. may be you didnt have answer for that
[no name] 5-Sep-13 8:42am    
How can I answer a question that does not exist? Can you point out to me exactly where in your posting any kind of a question was asked? Go ahead... point it out... I will wait. Just because someone provided you an answer based on a guess does not mean that you asked any kind of a question.

Solution 1 may fail on possible cultural differences.
Try:
C#
int price = int.Parse(priceTextBox.Text, CultureInfo.CurrentCulture);

You get the numeric value from this.
Throws a FormatException if the .Text is not an integer value.
Use whatever is appropriate instead of CultureInfo.CurrentCulture for different cultures,
e.g. CultureInfo.InvariantCulture

If you'd rather some different error handling for the parse failures:
C#
int price;
if (!int.TryParse(priceTextBox.Text, NumberStyles.Integer, CultureInfo.CurrentCulture, out price))
{
  // Whatever handling for not a simple integer goes here.
}
// price has the value here
 
Share this answer
 
Comments
Torakami 6-Sep-13 1:11am    
@Matt T Heffron you are absolutely right
Validate the input

C#
if (priceTextBox.Text.Contains(".")) {
    throw  new Exception("Decimal is not allowed.");
}
 
Share this answer
 
Comments
Torakami 5-Sep-13 7:08am    
thanks .. i think it will work ..
[no name] 5-Sep-13 7:11am    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900