Hi all,
I have two variable, count and totalcount, both are integer
My result is declared as float,
When I perform
result = count/totalcount;
it did not return a float as it should be.
Instead, it return 0 (eg 5/25)
How can I convert it to float
Thanks

how to convert int to float
mobigital
cdun2
int count, totalCount;
count = 5;
totalCount = 25;
float result = Convert.ToSingle(totalCount /count );
I hope this will help.
Best Regards,
Rizwan aka RizwanSharp
Gianni Marzaloni
Sorry Matthew,
You are right I just took the quesiton wrong as you can assume from my answer above.
Best Regards,
Rizwan aka RizwanSharp
Ro0ke
int b = 25;
float result = ((float)(a))/b;
result is 0.16
Grtz
Adriaan
DalekDAW
Hi,
Thanks for your solution.
Penicillin
totalCount/count will still be calculated in integer precision.
The correct answer is:
float result = count / (float)totalCount;
Criminet
Insead of type conversion of Variables u can simly use function
Convert.ToFloat(a/b);