convert double to <span class="Tn">ASCII</span> string

You're viewing an older version of this page (#3252). View the current version.

View versions (3)

NAME

<span class="Nm" id="ecvt">ecvt</span>, <span class="Nm" id="fcvt">fcvt</span>, <span class="Nm" id="gcvt">gcvt</span>

INTERFACE

#include <stdlib.h>

char ecvt ( double value, int ndigit, int * restrict decpt, int * restrict sign ) char fcvt ( double value, int ndigit, int * restrict decpt, int * restrict sign ) char gcvt ( double value, int ndigit, char *buf )

DESCRIPTION

<span class=""> These functions are provided for compatibility with legacy code. New code should use the reference:snprintf (3) function for improved safety and portability. </span> &#92;n &#92;n The ecvt , fcvt and gcvt functions convert the double precision floating-point number &#92;c value to a NUL-terminated <span class="Tn">ASCII</span> string. &#92;n &#92;n The ecvt function converts &#92;c value to a NUL-terminated string of exactly &#92;c ndigit digits and returns a pointer to that string. The result is padded with zeroes from left to right as needed. There are no leading zeroes unless &#92;c value itself is 0. The least significant digit is rounded in an implementation-dependent manner. The position of the decimal point relative to the beginning of the string is stored in &#92;c decpt. A negative value indicates that the decimal point is located to the left of the returned digits (this occurs when there is no whole number component to &#92;c value). If &#92;c value is zero, it is unspecified whether the integer pointed to by &#92;c decpt will be 0 or 1. The decimal point itself is not included in the returned string. If the sign of the result is negative, the integer pointed to by &#92;c sign is non-zero; otherwise, it is 0. &#92;n &#92;n If the converted value is out of range or is not representable, the contents of the returned string are unspecified. &#92;n &#92;n The fcvt function is identical to ecvt with the exception that &#92;c ndigit specifies the number of digits after the decimal point (zero-padded as needed). &#92;n &#92;n The gcvt function converts &#92;c value to a NUL-terminated string similar to the %g printf (3) format specifier and stores the result in &#92;c buf. It produces &#92;c ndigit significant digits similar to the %f printf (3) format specifier where possible. If &#92;c ndigit does allow sufficient precision, the result is stored in exponential notation similar to the %e printf (3) format specifier. If &#92;c value is less than zero, &#92;c buf will be prefixed with a minus sign. A decimal point is included in the returned string if &#92;c value is not a whole number. Unlike the ecvt and fcvt functions, &#92;c buf is not zero-padded.

RETURN VALUES

The ecvt , fcvt and gcvt functions return a NUL-terminated string representation of &#92;c value.

WARNINGS

The ecvt and fcvt functions return a pointer to internal storage space that will be overwritten by subsequent calls to either function. &#92;n &#92;n The maximum possible precision of the return value is limited by the precision of a double and may not be the same on all architectures. &#92;n &#92;n The reference:snprintf (3) function is preferred over these functions for new code.

SEE ALSO

printf (3) , strtod (3)

STANDARDS

The ecvt , fcvt and gcvt functions conform to