www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/11/01/02:30:04

Newsgroups: comp.os.msdos.djgpp
From: pjbk AT cee DOT hw DOT ac DOT uk (Peter JB King)
Subject: Re: Double to string anybody?
Message-ID: <E058uw.JyL@cee.hw.ac.uk>
Sender: news AT cee DOT hw DOT ac DOT uk (News Administrator)
Organization: Dept of Computing & Electrical Engineering, Heriot-Watt University, Scotland
References: <55142b$su AT news DOT sdsmt DOT edu> <5568bo$kdl AT hummin DOT sol DOT net>
Date: Thu, 31 Oct 1996 14:13:43 GMT
Lines: 31
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <5568bo$kdl AT hummin DOT sol DOT net> ksinner AT solaria DOT sol DOT net (Kenton E. Sinner) writes:
>Olav Kindt (oak9755 AT silver DOT sdsmt DOT edu) wrote:
>: Hi there,
>
>: I was wondering if djgpp had the equivalent of the gcvt() function from
>: BCC (Yeah i know..). Has anybody implemented these, or do I have to do it
>: myself. :-).
>
>: Any pointers to libs containg this one is appreciated.
>
>: PS. For those who doesn't know what i'm talking about: the gcvt function
>: converts a floating point number into a string (like itoa does for ints)
>: It is not standard ANSI C, so I don't think it is in the DJGPP package. At
>: least I couldn't find it.
>
>I had to write my own function for just this purpose.  But it's not hard.
>You just take the number modulo 10, which extracts the least significat
>digit, convert to the appropriate ascii character, divide by 10, and
>repeat the process until the division by 10 yields a zero residue.
>(I might not have remembered this correctly, as I don't have immediate
>access the the source I wrote, but you can get the gist of it.)
>
The suggested solution doesn't seem to take care of the fractional part.
Why not use sprintf?  It is more likely to be tested for all the funny
boundary value cases than any ad-hoc function that one hacks together!

-- 
Peter King, Computing & Electrical Eng.	 Internet: pjbk AT cee DOT hw DOT ac DOT uk
  Heriot-Watt University, Riccarton,      or  P DOT J DOT B DOT King AT heriot-watt DOT ac DOT uk
  Edinburgh EH14 4AS, Scotland
Phone: (+44) 131 451 3433               Fax: (+44) 131 451 3431

- Raw text -


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