Hie friends
I Have written this code in note pad i am trying to pass values via command prompt i.e
after compiling : csc cmdparams.cs then after
i am passing cmdparams 70 75 64 58 79 83 73 50
using System;
class cmdparams
{
static void Main(string[] args)
{
int sum = 0;
double per = 0;
foreach (string str in args)
sum += int.Parse(str);
per = Convert.ToInt32(sum * 100 / 750);
Console.WriteLine("sum is {0}", sum);
Console.WriteLine("percentage is {0}", per);
Console.ReadLine();
}
}
problem here is when i calculate percentage i am getting round figure like 73 but in reality its 73.6 ..
-->> Here i want to display output in cmd-prompt with decimals ??
Is there any way ?
Thank you


VulpesRank #55 · 29.2K reputationPosted Mar 1, 2013, 6:09 AM EST
per = Convert.ToInt32(sum * 100 / 750);
with this:
per = sum * 100.0 / 750.0;
Using double rather than integer constants (i.e. 100.0 rather than 100 etc) will force floating point arithmetic to be performed.
SUNIL GUTTARank #1,832 · 810 reputationPosted Mar 1, 2013, 7:06 AM EST
Hey can you provide ur gamil or any mail id so i can contact u for my silly silly problems rather i post here and mess up :)
VulpesRank #55 · 29.2K reputationPosted Mar 1, 2013, 2:45 PM EST
Also, this isn't a silly problem - it's something that can catch anyone out - but is easy to avoid as long as you think about each step in the calculation and whether you need to perform integer or floating point arithmetic.