Click here to Skip to main content
15,883,904 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi
I need to multiply values in two textbox
box3 datatype is Int
box4 datatype is float
box5 datatype is float(result)

C#
box5.Text = box3.Text * box4.Text;


Could you please help me to solve this

Thanks
Posted
Updated 7-Dec-11 21:40pm
v2

Try this one:
C#
float result = Convert.ToInt32(box3.Text) * Convert.ToSingle(box4.Text);
box5.Text = result.ToString();


Regards,
Eduard
 
Share this answer
 
Comments
Ganesan Senthilvel 8-Dec-11 4:05am    
this should be perfect
[no name] 8-Dec-11 4:13am    
thanks!
Sravan S 8-Dec-11 6:55am    
yeah, this is the best way to meet d requirement.
Sravan S 8-Dec-11 7:06am    
but still you will get error when the values entered are non numeric in the text boxes... :(
[no name] 8-Dec-11 21:11pm    
validation is not my problem anymore :)
box5.Text = (Convert.ToDouble(Convert.ToDouble(box3.Text) * Convert.ToDouble(box4.Text))).ToString();
 
Share this answer
 
The following would be more perfect because in the above solutions you will get an error when user enters non numeric values( like alphabets or symbols).But with the following code u wont get error. instead you will get value as 0.
C#
 int box3value;
float box4value,result;
int.tryparse(box3.text,out box3value);
float.tryparse(box4.text,out box4value);
result=box3value*box4value;
box5.text=result.tostring();

Hope this will help you for sure.
 
Share this answer
 
Convert.ToInt64(box5.Text) = Convert.toInt64(Convert.toInt32(box3.Text) * Convert.toInt64(box4.Text));

May br this'll help you out
 
Share this answer
 
Comments
Sravan S 8-Dec-11 6:54am    
by following this you will lose the float value as it will be converted into int. Say for value in box4 is 4.2 then Convert.toInt64(box4.Text) results in 4 which is not wat u want.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900