[aclug-L] Re: C question: double to string?
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Sun, Mar 05, 2000 at 12:11:19AM -0600, Brian Chapman wrote:
> Larry Bottorff wrote:
> >
> > Let's say I've got a double dnum = 10.55993 and I want to convert this
> > number to a char array, i.e, just the opposite of atof() so each digit
> > is put in a char in the array. How might I do such a thing?
> >
> > Larry Bottorff
> >
> > -- This is the discussion@xxxxxxxxx list. To unsubscribe,
> > visit http://tmp2.complete.org/cgi-bin/listargate-aclug.cgi
>
>
> now your thinking too hard! ;-)
>
> sprintf (buffer, "%f", number);
>
Of course this does assume that you are sure that your buffer is big
enough to hold the string. You might want to add some flags in the
format that limits the resulting string to a certain size, such as:
sprintf(buffer, "%10.10f", number);
-- This is the discussion@xxxxxxxxx list. To unsubscribe,
visit http://tmp2.complete.org/cgi-bin/listargate-aclug.cgi
|
|