Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Worthless_Knowledge

Char and Float (Simple)

This topic is 5270 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

Advertisement
Guest Anonymous Poster
Look up the itoa() and atoi() functions on Google.

You may need to cast the float to int first, or there may be a special function for floats, can someone enlighten us on that?

Share this post


Link to post
Share on other sites
sprintf(strTemp, "%s%f", strTemp, aNumber);

will result in strTemp containing "Hello2"

EDIT: Syncronous post with AP...

No, you use gcvt() for that.



(Stolen from Programmer One)
UNIX is an operating system, OS/2 is half an operating system, Windows is a shell, and DOS is a boot partition virus

[edited by - Dragon88 on February 6, 2004 4:33:16 PM]

[edited by - Dragon88 on February 6, 2004 4:33:54 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Don''t use itoa.

Share this post


Link to post
Share on other sites
quote:

Don''t use itoa.


yeah, don''t use itoa....or printf, cout, cin, include, define, main() and everything else.

Let him use what he/she wants to use ok. Unless you have a reason....in which you can include with your post.

my 3 cents.

Share this post


Link to post
Share on other sites
quote:

strcat strTemp with atof(aNumber). atof returns a char * version of a floating



No. atof returns a floating point variable.

try this:
char buffer[ 20 ];
fprintf( buffer, "%s%.2f", strTemp, aNumber );

printf( "%s", buffer );

Share this post


Link to post
Share on other sites
You are right and I''m retarded, sorry. sprintf is definitely the way to go. I''ll try to use my brain in future postings....

Share this post


Link to post
Share on other sites
So in essence, you are telling him what I said?



(Stolen from Programmer One)
UNIX is an operating system, OS/2 is half an operating system, Windows is a shell, and DOS is a boot partition virus

Share this post


Link to post
Share on other sites

#include<sstream>
#include<string>
#include<iostream>

int main()
{
float f=2.f;
std::ostringstream o;
o << "Hello" << f;
std::string s = o.str();
std::cout << s;
}


Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!