473,387 Members | 1,485 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

convert string to float

Hi

I'm having hard time finding a way to convert:

std::string input="10.5";
to
float input2;

help is appreciated,
Juhan Voolaid.
Jul 23 '05 #1
2 26908

"Juhan Voolaid" <ju*@hot.ee> wrote in message
news:cu**********@kadri.ut.ee...
Hi

I'm having hard time finding a way to convert:

std::string input="10.5";
to
float input2;


Try this link:
http://www.parashift.com/c++-faq-lit...al-issues.html
--
Sumit Rajan <su*********@gmail.com>
Jul 23 '05 #2
Juhan Voolaid wrote:
Hi

I'm having hard time finding a way to convert:

std::string input="10.5";
to
float input2;


There are two ways. C gives you strtod which converts between a char array
and double:
input2 = strtod(input.c_str(), NULL);

The C++ streams provide nice conversions to and from a variety of types.
The way to use strings with streams is to use a stringstream:

istringstream in(input);
input >> input2;
Jul 23 '05 #3

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

Similar topics

5
by: Cally | last post by:
Hello, I would like to convert a field from ntext field found in one database table to float field found in another database table. The reason why I want to do this is a long one. I have...
4
by: jaijai_kumar | last post by:
Select Cast('100.1234' as float) give me the result 100.1234 Now when I convert it back to char I want exactly 100.1234 Select Convert(char(100),Cast('100.1234' as float)) Gives me 100.123 (Here...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
2
by: Chi Tang | last post by:
Hi, I try to convert a string to a float but it alway comes out with extra value. For example, the string input is '12.6' but the output is '12.6000003814697' The following is my code to do...
7
by: shellon | last post by:
Hi all: I want to convert the float number to sortable integer, like the function float2rawInt() in java, but I don't know the internal expression of float, appreciate your help!
2
by: lisasahu | last post by:
how to convert float to string like there is atof atoi and itoa but is ther any method to convert float to string
0
by: jeff_rowa | last post by:
Hi guyz, Could anyone please tell me how can I convert an array of floats to a string? I know that I can use this code to convert one float to a string but what is the best way for an array of...
7
by: tereglow | last post by:
Hello, I am a complete newbie to Python and am accustomed to coding in PHP/ Perl/Shell. I am trying to do the following: I have a string: cpuSpeed = 'Speed: 1000000000' What I would...
12
by: Peter | last post by:
Trying to convert string to byte array. the following code returns byte array of {107, 62, 194, 139, 64} how can I convert this string to a byte array of {107, 62, 139, 65} ...
9
by: Marco Nef | last post by:
Hi there I'm looking for a template class that converts the template argument to a string, so something like the following should work: Convert<float>::Get() == "float"; Convert<3>::Get() ==...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.