[net.unix] Converting floats to ascii and vice versa

zellich@almsa-1.ARPA (04/25/84)

From:      Rich Zellich <zellich@almsa-1.ARPA>

Does anyone have subroutines for converting an ascii string to a float or double
and for converting a float or double to an ascii string (like atoi and itoa)?
-Rich

gwyn@BRL-VLD.ARPA (04/25/84)

From:      Doug Gwyn (VLD/VMB) <gwyn@BRL-VLD.ARPA>

The C library contains ASCII<->floating-point converters:
	atof	convert ASCII string to floating-point number
	scanf	convert formatted input

zellich@almsa-1.ARPA (04/25/84)

From:      Rich Zellich <zellich@almsa-1.ARPA>

To all those who replied about atof(), sscanf(), and sprintf(), thank you.
I knew about them but for some reason couldn't find atof on our system when
I looked for it (it's there, though, because when I looked into sscanf and
_doprint, it is used, and replacing sscanf with atof works just fine).  As
for sscanf and sprintf, it just seemed there ought to be a less convoluted
way of handling a single variable of known type (in the case of sscanf, of
course, there is: atof).
Cheers,
Rich

mike@BRL-TGR.ARPA (04/26/84)

From:      Mike Muuss <mike@BRL-TGR.ARPA>

How about atof() and sprintf() ?
	-Mike

moss@BRL-VLD.ARPA (04/26/84)

From:      Gary S Moss ~Software Development Team~ <moss@BRL-VLD.ARPA>

Rich --
	As Mike said, 'sprintf()' and 'atof()' are available, or more
general than 'atof()' is 'fscanf()' and 'sscanf()', that is unless you
don't want to load in the 'printf()' library.  Read section 3 of your
UNIX User's Manual.

-- Moss.

ted@usceast.UUCP (Ted Nolan) (05/01/84)

<1 = 0.99999999>
There are several ways to  convert floats to ascii and vice versa.
The query asked specifically (sp?) for functions like atoi and itoa.
Our version 7 system has an atof(3) function available, which is 
like atoi for floats.  If this is not present K&R give an atof 
function on page 69 of the C book .

However, I find that the string formatting commands sprintf and
sscanf give a much nicer and more general way to do this type of 
conversion

-- 
--------------------------------------------------------------------------------
Ted Nolan		  		usceast!ted
6536 Brookside Circle
Columbia, SC 29206			(feather the rast!)
--------------------------------------------------------------------------------

chris@umcp-cs.UUCP (05/03/84)

Also, if you don't want stdio for some reason and can't use *printf
to convert to ASCII, there's ecvt(), fcvt(), and gcvt() (which are,
of course, what printf uses internally).
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci (301) 454-7690
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris@umcp-cs		ARPA:	chris@maryland