Path: utzoo!attcan!uunet!zaphod.mps.ohio-state.edu!usc!elroy.jpl.nasa.gov!thyme!kaleb From: kaleb@thyme.jpl.nasa.gov (Kaleb Keithley ) Newsgroups: comp.lang.c Subject: Re: Efficient way to transform float to string Message-ID: <1990Dec10.165908.16922@thyme.jpl.nasa.gov> Date: 10 Dec 90 16:59:08 GMT References: <5906@stpstn.UUCP> <537@taumet.com> Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 40 Stepping into the middle of the thread. On Sun; there is econvert and related functions. econvert() converts the value to a null-terminated string of ndigit ASCII digits in buf and returns a pointer to buf. buf should contain at least ndigit+1 characters. The posi- tion of the radix character relative to the beginning of the string is stored indirectly through decpt. Thus buf == "314" and *decpt == 1 corresponds to the numerical value 3.14, while buf == "314" and *decpt == -1 corresponds to the numerical value .0314. If the sign of the result is nega- tive, the word pointed to by sign is nonzero; otherwise it is zero. The least significant digit is rounded. fconvert works much like econvert, except that the correct digit has been rounded as if for sprintf(%w.nf) output with n=ndigit digits to the right of the radix character. ndigit can be negative to indicate rounding to the left of the radix character. The return value is a pointer to buf. buf should contain at least 310+max(0,ndigit) characters to accomodate any double-precision value. gconvert() converts the value to a null-terminated ASCII string in buf and returns a pointer to buf. It produces ndigit significant digits in fixed-decimal format, like sprintf(%w.nf), if possible, and otherwise in floating- decimal format, like sprintf(%w.ne); in either case buf is ready for printing, with sign and exponent. The result corresponds to that obtained by (void) sprintf(buf, "%w.ng", value); -- Kaleb Keithley Jet Propulsion Labs kaleb@thyme.jpl.nasa.gov You can please all of the people some of the time,