delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2003/03/10/10:09:15

Message-ID: <20030310150733.47704.qmail@web13001.mail.yahoo.com>
Date: Mon, 10 Mar 2003 07:07:33 -0800 (PST)
From: Thomas Tutone <thomas8675309 AT yahoo DOT com>
Subject: Re: float version of itoa
To: djgpp AT delorie DOT com
MIME-Version: 1.0

"Joel_S" <jbs30000 DOT news DOT invalid AT web2news DOT net> wrote: 

> I don't think there's a built in version of a float 
> to string 
> conversion routine, but does anybody have any code, 
> or know a library 
> that contains such a routine?  Thanks.

If you're using C++, just use an ostringstream:

#include <string>
#include <sstream>

int main()
{
	using namespace std;
	float f = 7.25;
	ostringstream os;
	os << f;
	string s = os.str();
	// s now holds the string 
	//    representation of f
}

For more info, take a look at sections 38.1 - 38.3 of
the C++ FAQ:
http://www.parashift.com/c++-faq-lite/

Best regards,

Tom

__________________________________________________
Do you Yahoo!?
Yahoo! News - Today's headlines
http://news.yahoo.com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019