Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hallo every one,
if iwant to give a textbox afloat value how can ido that
for examble if ihave these
C#
int p,q;
float a,b,c,d;
a=float.parse(textbox1.text);
b=float.parse(textbox2.text);
if(p<q)
{
c=a;
d=b;
}
else
{
c=b;
d=a;
}
textbox3.text=c;//here the error 
textbox4.text=d;//also here

can you help me to fix this
thanks in advance

:)
Posted

You are trying to assign a float type value to a string text box text attribute.
Thus you get the error.

Use the Convert.ToString() method.
C#
textbox3.text=Convert.ToString(c);
textbox4.text=Convert.ToString(d);
 
Share this answer
 
v2
Comments
Rahul Rajat Singh 9-Apr-12 4:03am    
Why use convert.tostring(). it can be done by simply calling .tostring on the float type
Abhinav S 9-Apr-12 8:02am    
tostriong() will throw an error in case c is null. So its always a better practice to use Convert.ToString().
VJ Reddy 9-Apr-12 4:07am    
+5
Abhinav S 9-Apr-12 8:02am    
Thank you.
do this

C#
textbox3.text=c.ToString();
 
Share this answer
 
Comments
VJ Reddy 9-Apr-12 4:07am    
+5
Use string.format or ToString method of float as below

C#
//N2 format for printing 2 decimal places. 
//or use other format as required
textbox3.text=string.Format("{0:N2}",c);
textbox4.text=string.Format("{0:N2}",d);
//or
textbox3.text=c.ToString("N2");
textbox3.text=d.ToString("N2");
 
Share this answer
 

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