Hi,
I am just doing a divide and multiplication process like below;
-----------
double a=2;
double b=3;
double c =(a/b) *100;
-----------
The result is "66.666666666666657". I wanna show only first 2 character from start, "66". How can I do that?
Loading
Datta KharadPosted Nov 2, 2011, 3:27 AM
If you want result like 66 then you should typecasting from double to int. You can try this code.....
double a=2;
double b=3;
int c=(int)((a/b)*100);
Result c=66.
If you got solution then Mark as Accepted Answer.
yokzuPosted Nov 2, 2011, 5:04 AM
Suthish NairPosted Nov 2, 2011, 4:30 AM
double a1 = 2;
double b1 = 3;
double c1 = (a1 / b1) * 100;
Console.WriteLine(Math.Floor(c1));
double a2 = 2;
double b2 = 3;
double c2 = (a2 / b2) * 100;
Console.WriteLine((int)c2);
Console.ReadLine();