Click here to Skip to main content
11,645,087 members (64,360 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 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
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
0 OriginalGriff 700
1 jyo.net 494
2 Sergey Alexandrovich Kryukov 449
3 Afzaal Ahmad Zeeshan 444
4 CPallini 426
0 OriginalGriff 1,065
1 Sergey Alexandrovich Kryukov 703
2 Afzaal Ahmad Zeeshan 702
3 DamithSL 681
4 CPallini 595


Advertise | Privacy | Mobile
Web02 | 2.8.150731.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