Sign in to follow this  

string to Float

This topic is 2315 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How would i change a string of contiguous number characters Ex: [color="#ff0000"]"-14.000"[/color] or[color="#48d1cc"] [color="#008000"]"14.000"[/color] [/color]. I mean[color="#ff0000"] string dog("-14.000");[/color] or [color="#008000"]string dog("14.000");[/color]

What process would i use to change[color="#000080"]([/color] [color="#ff0000"]string dog("-14.000");[/color] or [color="#008000"]string dog("14.000");[/color] [color="#000080"] ) [/color]into a ( [color="#ff0000"]float -14.000[/color] or [color="#008000"]float 14.000 [/color] )

I'm using c++. Would I us some sort of type casting or is there a different way or more efficient way?

Share this post


Link to post
Share on other sites
Something like this does the trick for me:
[code]std::string mynumber = "0.123";
float myfloat = ::atof(mynumber.c_str());
[/code]


Also... Search before posting ;)
http://www.gamedev.net/topic/401253-string-to-float/

Share this post


Link to post
Share on other sites

This topic is 2315 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this