Click here to Skip to main content
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 Sarvesh Kumar Gupta 228
1 CHill60 200
2 Sergey Alexandrovich Kryukov 153
3 DamithSL 153
4 Peter Leow 145


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