Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to check if Result = 3.44444
then check Result is int or float form
Posted
Updated 19-Mar-12 22:13pm
v3
Comments
V. 20-Mar-12 3:54am    
what type is Result?
Oshtri Deka 20-Mar-12 4:05am    
Edit:
Removing unnecessary pre tags.

1 solution

If the data type od Result is string:

Use the int32 TryParse method[^] or the float TryParse method to figure out the type of your value.

E.g. bool result = Int32.TryParse(Result, out number);

So you can use
if (Int32.TryParse(Result, out number))
{
  //Then value is integer 
}
 
Share this answer
 
v3
Comments
Shruthi.BT 20-Mar-12 4:07am    
int Ratings = Convert.ToInt32(ds.Tables[0].Rows[0]["StarCount"].ToString());
int People = Convert.ToInt32(ds.Tables[0].Rows[0]["PeopleCount"].ToString());
float f1 = (float)Ratings;

float r1 = f1 / People;
Result = Convert.ToString(r1);
// Result = Result.Substring(0, 3);

// double result = (double)r1;
//float Toatl = Ratings / People;
Result = Result.ToString();
//Result = Int32.TryParse(Result, out number);
if (Int32.TryParse(Result, out number))
{
//Then value is integer
}
Result = Result.Substring(0, 3);
TotalPPl = People.ToString();

is the code used for rating so here Result=Result.Substring(0,3)
i want to include inside if condition where if Result is 10 it should not
go to Result=Result.Substring(0, 3);

so, i used above condition but out number showing error so can u please tell how to include if condition in above code...

thanks in advance!
Shahin Khorshidnia 20-Mar-12 4:15am    
Define number before using it in TryParse:

int32 number = 0;
if (Int32.TryParse(Result, out number))
{
//Then value is integer
}
Oshtri Deka 20-Mar-12 4:16am    
It works great on strings. Just to make it clear to OP or to some beginner who shall stumble upon this in future, you should provide write Result.ToString().
5.
Abhinav S 20-Mar-12 4:21am    
Thanks. Good point.
Shruthi.BT 20-Mar-12 6:54am    
thank u all it worked!!

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