Very small problem - but i had stucked here
-
Convert _Namecnt and _Totalcnt to decimals rather than the result of the calculation, i.e.
decimal Pctmatch = (Convert.ToDecimal(_Namecnt) / Convert.ToDecimal(_Totalcnt)) * 100;
-
Hi friends, Its very silly problem. But still it scares me. int _Totalcnt = 62; int _Namecnt = 31; decimal Pctmatch = Convert.ToDecimal((_Namecnt / _Totalcnt) * 100); I am getting value for Pctmatch as '0'. why it showing wrong. How can i get exact decimal value there?
G. Satish
-
Hi friends, Its very silly problem. But still it scares me. int _Totalcnt = 62; int _Namecnt = 31; decimal Pctmatch = Convert.ToDecimal((_Namecnt / _Totalcnt) * 100); I am getting value for Pctmatch as '0'. why it showing wrong. How can i get exact decimal value there?
G. Satish
-
Do not spam:mad:
Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
Shivass wrote:
Please Don't SPAM. This is second time you are doing the same thing. X|
cheers, Abhijit CodeProject MVP Web Site:abhijitjana.net View My Recent Article
-
Hi friends, Its very silly problem. But still it scares me. int _Totalcnt = 62; int _Namecnt = 31; decimal Pctmatch = Convert.ToDecimal((_Namecnt / _Totalcnt) * 100); I am getting value for Pctmatch as '0'. why it showing wrong. How can i get exact decimal value there?
G. Satish
I can't believe you got this many replies and not the right answer, or at least, not a proper explanation ( that I could see ). decimal PctMatch = _Namecnt/(Decimal)_Totalcnt * 100 If you divide by a decimal, you will get a decimal answer. If you divide by an int, it gets rounded and you get an int, which is THEN converted to decimal, but the decimal part has already been discarded.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
you are a retard
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
Convert _Namecnt and _Totalcnt to decimals rather than the result of the calculation, i.e.
decimal Pctmatch = (Convert.ToDecimal(_Namecnt) / Convert.ToDecimal(_Totalcnt)) * 100;
ya, perfect. Its working now. But how to take precesion here. i am getting value for Pctmatch = 76.876789989999 how can i get only 2 values after decimal?
G. Satish
-
I can't believe you got this many replies and not the right answer, or at least, not a proper explanation ( that I could see ). decimal PctMatch = _Namecnt/(Decimal)_Totalcnt * 100 If you divide by a decimal, you will get a decimal answer. If you divide by an int, it gets rounded and you get an int, which is THEN converted to decimal, but the decimal part has already been discarded.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
Thank you christian for your detailed explaination.
G. Satish
-
ya, perfect. Its working now. But how to take precesion here. i am getting value for Pctmatch = 76.876789989999 how can i get only 2 values after decimal?
G. Satish
ya, i got the answer. By converting to string as Pctmatch.ToString("N2");
G. Satish