how to divide two numbers in c# [Resolved]

Posted by Tarawatruchika under C# on 5/12/2012 | Points: 10 | Views : 10680 | Status : [Member] | Replies : 7
i want to divide two numbers and then multiply 20 in result value.

my code is:
mm = Convert.ToInt32(ds.Tables[0].Rows[0][1].ToString());
a = (TextBox)row.FindControl("T1");
m = (float)(Convert.ToInt32(a.Text) / mm) * 20;

for example:
a=20, mm=40
so m should be (20/40)*20=10.

but in programming, divide ("/") give 0 when we try 20/40 instead of 0.5. so i always get value of m is 0 except a=40.
how can i do this? i want m=10, not 0.




Responses

Posted by: Moaa Memo on: 5/12/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
hi
in windows form app
drag 3 text box
and one bottm
in butom click event write this code
double m = Convert.ToDouble(textBox1.Text);
double j = Convert.ToDouble(textBox2.Text);
double r = Convert.ToDouble((m / j) * 20);
textBox3.Text = r.ToString();


Tarawatruchika, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 5/12/2012 [Member] Silver | Points: 25

Up
0
Down
declare variable 'm' as float or double..

Regards,
Singaravel M

Tarawatruchika, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 5/12/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
float m=convet.ToFloat(textbox1.Text);
float n=convert.ToFloat(textbox2.Text);
float res=convert.ToFloat((m/n)*20);
textbox3.Text=res.ToString();

Thanks & Regards
Hari

Tarawatruchika, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tarawatruchika on: 5/12/2012 [Member] Starter | Points: 25

Up
0
Down
convert.ToFloat is not any method.
i got my solution with "double"

Tarawatruchika, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tarawatruchika on: 5/12/2012 [Member] Starter | Points: 25

Up
0
Down
i already declared it as a "float".
now i declared it as "double". now i got my answer. thanks. :)

Tarawatruchika, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tarawatruchika on: 5/12/2012 [Member] Starter | Points: 25

Up
0
Down
thank u. :)
declaring m as "double" works.

Tarawatruchika, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response