954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

string to double

i am using 'atof' function to convert string into double but it shows the correct value if the string length is 17(max). is ther any function if string length is more than 17?

shanki himanshu
Light Poster
37 posts since Dec 2010
Reputation Points: 9
Solved Threads: 1
 

Does the string represent a valid double value? If not, then you won't find a conversion function that works without first getting a library that supports larger floating point values.

deceptikon
Indubitably
Administrator
632 posts since Jan 2012
Reputation Points: 119
Solved Threads: 105
 

the string contains only the numerals from 0-9.

shanki himanshu
Light Poster
37 posts since Dec 2010
Reputation Points: 9
Solved Threads: 1
 

That's only a partial test. A string can contain only digits and still be out of range for the target type. If it's out of range, trying to convert the string to the target type will be undefined.

deceptikon
Indubitably
Administrator
632 posts since Jan 2012
Reputation Points: 119
Solved Threads: 105
 

I was going to roll my own, but this works just fine.
http://www.fredosaurus.com/notes-cpp/algorithms/string2int-ans.html

Adapt it to eliminate the bools if you need to, but the code should work just fine.

DeanMSands3
Junior Poster
185 posts since Jan 2012
Reputation Points: 37
Solved Threads: 26
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You