Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to convert float type to string


float prev
float added
float total



string previous =prevtxt.Text;
string added = addedtxt.Text;
string total = totaltxt.Text;

update(prev, added, total);
Posted
Comments
Andreas Gieriet 27-Jan-13 17:32pm    
Do not add your comment as a solution! Please delete you solution #2 and add the comment to the soultion #1 by pressing the [Have a question or Comment?] button.
Andi

Convert float to string e.g. prev.ToString() but I suspect you also want it the other way around...
C#
float.TryParse(prevtxt.Text, out prev);


Or
C#
prev.ToString("0.00"); 
if you want to format it ... try looking up the help on ToString() or look at the intellisense prompts
 
Share this answer
 
v2
Comments
Andreas Gieriet 27-Jan-13 17:34pm    
You are missing the out in the TryParse call.
Cheers
Andi
CHill60 27-Jan-13 17:37pm    
Cheers - was in the process of adding it - although I will confess to deliberate typos in most of my answers if I suspect a straight copy-paster ;-p
[no name] 27-Jan-13 21:29pm    
+5
String to float: float.TryParse(...), e.g.
C#
if (!float.TryParse(previous, out prev))
{
    // do some UI error handling
}
else
{
    // do the correct case
}

Float to string:
C#
string s = prev.ToString();

Cheers
Andi
 
Share this answer
 
Hi,

Please be use .ToString() method for converting into String type..
 
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