473,671 Members | 2,211 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting a float to a string

Hello,

float.parse(MyS tring)

seems to work to convert a string to a float, but how do I change it
back?

e.g.

(string) (Myfloat1 - Myfloat2)

doesn't seem to work.

Mar 17 '06 #1
5 2472
myFloat.ToStrin g() should do it..

Mar 17 '06 #2
You can call the ToString method on the float.
http://msdn.microsoft.com/library/de...tringtopic.asp

--
Tim Wilson
..NET Compact Framework MVP

<er**********@g mail.com> wrote in message
news:11******** *************@z 34g2000cwc.goog legroups.com...
Hello,

float.parse(MyS tring)

seems to work to convert a string to a float, but how do I change it
back?

e.g.

(string) (Myfloat1 - Myfloat2)

doesn't seem to work.

Mar 17 '06 #3
Thanks, that works. The intellisense seems to choke on it though:

float float1;
float float2;

string mystring;

mystring=(float 1-float2).ToStrin g();

When I type the "." after (float1-float2) I don't see a list of
methods.

If I type in ".ToString( );" manually it seems to compile though.

-Eric

Mar 17 '06 #4
Yeah. Intellisense does not like to show options in this situation, I guess.
I've noticed that too. But, as you said, it's valid and the compiler handles
it as it should.

--
Tim Wilson
..NET Compact Framework MVP

<er**********@g mail.com> wrote in message
news:11******** **************@ p10g2000cwp.goo glegroups.com.. .
Thanks, that works. The intellisense seems to choke on it though:

float float1;
float float2;

string mystring;

mystring=(float 1-float2).ToStrin g();

When I type the "." after (float1-float2) I don't see a list of
methods.

If I type in ".ToString( );" manually it seems to compile though.

-Eric

Mar 17 '06 #5
just : float myFloat = float1-float2;
string str;
str = myFloat.ToStrin g();
that's ok.
---
Posted via www.DotNetSlackers.com
Mar 22 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
4616
by: Bushido Hacks | last post by:
Hey c.l.c++ and/or c.g.a.opengl posters, How do I convert a hexidecimal string, traditionally used for defining colors with HTML, into a floating point array? In other words, how do I convert this: char* hex = "#FF9933"; into this:
1
1867
by: Meya-awe | last post by:
Hello there, I am using a 3rd party library and a function which requires a float value in one of its methods. My data is in a string format and i tried using Convert.ToDouble and Convert.ToSingle, but didn't work either way. The value of string is "-57475.4531". The help in VS .NET 2003 tells me that these convert methods will return double and single precision float point values respectively but i needed to also cast the return to the...
5
7867
by: vivekaseeja | last post by:
Hi , Trying to convert a string value to a float value after reading the value from an XML file , but not sure what function to use. The following only works for integers Int32.Parse (readXml.Value) ; Any suggestions for an alternate function ..
3
1838
by: Jim Langston | last post by:
I have a CSkill class which is rather complex as it is recursive. That is: class CSkill { public: CSkill( std::string Name, float Value ): Name_( Name ), Value_( Value ) {}; void Update( const std::string& Name, const float Value ); float Value( const std::string& Name ) const; float Sum( const std::string& Name ) const;
3
41234
by: pipe.jack | last post by:
I'm trying to convert string to float and my float after conversion is 0 (zero). Here is my code: $c = $currencies->format($cart->show_total()); echo gettype($c); echo (float)$c; $c = 39.59 gettype($c) = string echo (float)$c; = 0
3
3249
by: psbasha | last post by:
Hi , When ever we read any data from file ,we read as a single line string ,and we convert the respective field data available in that string based on the data type ( say int,float ). Please suggest me which is the best way of handling the file data. I- Method: ---------------- Store as single line string data's(upto end of file ) in a list and make use of this string list for the entire application.
12
11278
by: joestevens232 | last post by:
Okay, Im having some problems with my code. Im trying to use the <cstdlib> library and im trying to convert string data at each whitespace slot. I think if you see my code you'll get what im trying to do : #include <cstdlib> #include <iostream> #include <string> #include <vector> #include <fstream> using namespace std; using std::ifstream; using std::ofstream;
10
3236
by: Hank Stalica | last post by:
I'm having this weird problem where my code does the following conversion from string to float: 27000000.0 -27000000.00 2973999.99 -29740000.00 2989999.13 -2989999.25 The number on the left is the string I get after tokenizing a bigger string. The number on the right is the number I get after the conversion.
7
4466
by: DirtyRasa | last post by:
Here is what my professor told me to to. Write a function that converts a string to a float and returns a float. Test your function by entering f4 and with 4f. Both should say Data entered was not a number. Try again. and ask the user to type in another number. Here's what I have so far. Code:
7
4779
by: ma740988 | last post by:
Consider the equation (flight dynamics stuff): Yaw (Degrees) = Azimuth Angle(Radians) * 180 (Degrees) / 3.1415926535897932384626433832795 (Radians) There's a valid reason to use single precision floating point types. The number of decimal digits guaranteed to be correct on my implementation is 6. (i.e numeric_limits < float >::digits10 = 6 ) If I'm reading the IEEE standard, I'd could paraphrase the issue
0
8914
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8820
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8598
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7433
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6223
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5695
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1809
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.