delorie.com/djgpp/doc/libc/libc_311.html | search |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
#include <stdlib.h> char * fcvtbuf (double value, int ndigits, int *decpt, int *sign, char *buf) |
This function converts its argument value into a null-terminated
string in buf with ndigits digits to the right of the
decimal point. ndigits can be negative to indicate rounding to
the left of the decimal point. buf should have enough space to
hold at least 310+max(0,ndigits)
characters.
Note that, unlike ecvtbuf
(see section ecvtbuf), fcvtbuf
only
counts the digits to the right of the decimal point. Thus, if
value is 123.45678 and ndigits is 4, then ecvtbuf
will produce "1235", but fcvtbuf
will produce "1234568" (and
*decpt will be 3 in both cases).
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).
A pointer to buf.
ANSI/ISO C | No |
POSIX | No |
#include <stdlib.h> #include <stdio.h> #include <math.h> char vbuf[20]; int fsign, fdecpt; fcvtbuf (M_PI, 5, &fdecpt, &fsign, buf) /* This will print " 314159". */ printf ("%c%s", fsign ? '-' : ' ', buf); |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
webmaster | delorie software privacy |
Copyright © 2004 | Updated Apr 2004 |