Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
2.00/5 (4 votes)
See more:
How to convert float datatype to string datatype

[edit]Please do not use UPPER CHAR[/edit]
Posted
Updated 5-Jun-11 22:18pm
v2

Like this:

float foo = 32.2;
string bar = foo.ToString();


You might want to take a look at this link[^] it helps you specifiy how you want the string to be formatted (decimal points, separators etc).
 
Share this answer
 
Comments
shaimaa 2 5-Jun-11 18:37pm    
txt_credite.Text = dr["credit"].ToString();
THAT DATATYPE OF CREDIT IS FLOAT AND I WANT TO CONVERT IT TO STRING HOW WRITE IT
Christian Graus 5-Jun-11 20:43pm    
first of all, either your caps lock is broken, or you are very rude, or you have no idea what is acceptable on the internet. THIS IS SHOUTING. Second, the code you've posted, works. Every object has a ToString, which converts it to a string. In this case, you're going from object to string, without it ever being a float, but that should not matter. If you didn't know about Tostring, then you should not be writing code, you should be reading beginner books.
Sergey Alexandrovich Kryukov 5-Jun-11 21:00pm    
No! dr could be anything indexed with string; and dr["credit"] also can be anything.
Do not ask questions on the code you don't show.
Also, you got an answer. Don't pretend you did not.
--SA
You can also try
string u = Convert.ToString(foo);
 
Share this answer
 
hi,

C#
float aa = 1000;
            string bb = aa.ToString();



this will help
 
Share this answer
 
Try this

float foo = 32;
String s =foo.ToString()
MessageBox.Show(s)
Regards,
Lakshmi narayanan.S
 
Share this answer
 
Comments
fjdiewornncalwe 6-Jun-11 9:26am    
Please read the answers already given before posting a duplicate. Just vote on the one you agree with and leave a comment to that one. It helps to clarify a good answer to the OP.
shaimaa 2 6-Jun-11 11:58am    
I think i did not explain my problem in good way i search about solve my problem but all of that answer not what i want i make project and i define some parameter as float and in coding in windows form i must make all parameter as string i make some parameter data type as datetime i write statement like that[ dateTimePicker2.Value = DateTime.Parse(dr["hireDate"].ToString());] to convert data type to string so i want to repeat that but with change that what i want to convert is float not datetime
For displaying a numeric value in a label or text box on a winform you can convert a float value by using the string format, which will convert a float to a formatted string value.

For example: I display a double float value for a ratio and display it on a winform as shown below.

lblRatio.Text = string.Format("{0:0.0000}", DATclass.dRatio);


http://msdn.microsoft.com/en-us/library/fht0f5be.aspx[^]
 
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