delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2003/03/10/20:00:34

From: MCheu <mpcheu AT yahoo DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: float version of itoa
Organization: Metronome
Message-ID: <hlcq6v4kp6mep4vniqmjk7kq6i8cm0uc25@4ax.com>
References: <18555N369 AT web2news DOT com>
X-Newsreader: Forte Agent 1.92/32.572
MIME-Version: 1.0
Lines: 34
Date: Mon, 10 Mar 2003 19:56:21 -0500
NNTP-Posting-Host: 209.188.65.172
X-Trace: localhost 1047344239 209.188.65.172 (Mon, 10 Mar 2003 17:57:19 MST)
NNTP-Posting-Date: Mon, 10 Mar 2003 17:57:19 MST
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

On Mon, 10 Mar 2003 03:12:49 +0100, "Joel_S"
<jbs30000 DOT news DOT invalid AT web2news DOT net> wrote:

>I don't think there's a built in version of a float to string conversion
>routine, but does anybody have any code, or know a library that contains
>such a routine?  Thanks.

If you were going the other way, it might be more of a challenge, but
sprintf will probably do what you're asking.  The following code is
not guaranteed to run or even compile, but you get the idea.

#include <stdio.h>
#include <string.h>

int main (void)
{
  /* declare my vars */
  float myFloat = 1.23456f;
  char myString[1000];

  /* do conversion */
  sprintf (myString, "%f",myFloat);
  
  /* dump output */
  puts (myString);

  return 0;
}


-----------
Thanks

MCheu

- Raw text -


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