Click here to Skip to main content
11,709,220 members (71,698 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WinForm
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 11:05am
Comments
Andreas Gieriet at 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 4

Hi,

Please be use .ToString() method for converting into String type..
  Permalink  
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 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 at 27-Jan-13 17:34pm
   
You are missing the out in the TryParse call.
Cheers
Andi
CHill60 at 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

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 565
1 OriginalGriff 244
2 Maciej Los 225
3 Peter Leow 219
4 Mika Wendelius 160
0 OriginalGriff 9,348
1 Sergey Alexandrovich Kryukov 8,727
2 CPallini 5,189
3 Maciej Los 4,991
4 Mika Wendelius 3,856


Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 27 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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