Click here to Skip to main content
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
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 27-Jan-13 12:05pm
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

Or
prev.ToString("0.00"); 
if you want to format it ... try looking up the help on ToString() or look at the intellisense prompts
  Permalink  
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

String to float: float.TryParse(...), e.g.
if (!float.TryParse(previous, out prev))
{
    // do some UI error handling
}
else
{
    // do the correct case
}
Float to string:
string s = prev.ToString();
Cheers
Andi
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Hi,

Please be use .ToString() method for converting into String type..
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Web01 | 2.8.160204.4 | Advertise | Privacy
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100