www.delorie.com/djgpp/doc/libc/libc_372.html   search  
libc.a reference

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

gcvt

Syntax

 
#include <stdlib.h>

char * gcvt (double value, int ndigits, char *buf)

Description

This function converts its argument value into a null-terminated string of ndigits significant digits in buf. buf should have enough space to hold at least ndigits + 7 characters. The result roughly corresponds to what is obtained by the following snippet:

 
 (void) sprintf(buf, "%.*g", ndigits, value);

except that trailing zeros and trailing decimal point are suppressed.

The least-significant digit in buf is rounded.

ecvtbuf produces the string "NaN" if value is a NaN, and "Inf" if value is an infinity.

Return Value

A pointer to buf.

Portability

ANSI/ISO C No
POSIX No

Example

 
  #include <stdlib.h>
  #include <stdio.h>
  #include <math.h>

  char vbuf[20];

  /* This will print " 3.14159".  */
  printf ("%s", gcvt (M_PI, 5, buf));


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2004   by DJ Delorie     Updated Apr 2004