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

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

ecvtbuf

Syntax

 
#include <stdlib.h>

char * ecvtbuf (double value, int ndigits, int *decpt, int *sign,
                char *buf)

Description

This function converts its argument value into a null-terminated string of ndigits digits in buf. buf should have enough space to hold at least ndigits + 1 characters.

The produced string in buf does not include the decimal point. Instead, the position of the decimal point relative to the beginning of buf is stored in an integer variable whose address is passed in decpt. Thus, if buf is returned as "1234" and *decpt as 1, this corresponds to a value of 1.234; if *decpt is -1, this corresponds to a value of 0.01234, etc.

The sign is also not included in buf's value. If value is negative, ecvtbuf puts a nonzero value into the variable whose address is passed in sign; otherwise it stores zero in *sign.

The least-significant digit in buf is rounded.

ecvtbuf produces the string "NaN" if value is a NaN, and "Inf" or "Infinity" if value is an infinity (the longer form is produced when ndigits is 8 or more).

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];
  int esign, edecpt;

  ecvtbuf (M_PI, 5, &edecpt, &esign, buf)
  /* This will print " 31416".  */
  printf ("%c%s", esign ? '-' : ' ', buf);


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