[comp.lang.c] converting a float to a character string

hartkopf@tramp.Colorado.EDU (Jeff Hartkopf) (08/13/89)

Does anyone have a function or know where I could get one that will convert
a double (or at least a float) to a character string?  It looks like a hard
problem to me, one that would take quite a while to write, and I might never
get it working.  If the double was fairly small (say 8 or 10 digits or so)
the character string should just contain all the digits and decimal point,
but if it was very huge (or very tiny) the string should contain the e+ or e-
representation.

I'd really appreciate any help on this.  Thanks very much.


Jeff Hartkopf

Internet:
hartkopf@tramp.Colorado.EDU

ping@cubmol.BIO.COLUMBIA.EDU (Shiping Zhang) (08/13/89)

In article <10720@boulder.Colorado.EDU> hartkopf@tramp.Colorado.EDU (Jeff Hartkopf) writes:
>Does anyone have a function or know where I could get one that will convert
>a double (or at least a float) to a character string?  It looks like a hard


>Jeff Hartkopf

>Internet:
>hartkopf@tramp.Colorado.EDU


I think you can use sprintf() to achieve the task.
Of course, the formate argument of this function should be different
for varibles with differrent size of values according to your requests.
So you would have to take conditional test on the values of the varibles
before you call sprintf() with desired formate.



-ping