Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

ecvt, fcvt, gcvt - convert floating-point number to string

&pagelevel(4)&pagelevel

Syntax

#include <stdlib.h>

char *ecvt(double value, int ndigit, int *decpt, int *sign);

char *fcvt (double value, int ndigit, int *decpt, int *sign);

char *gcvt (double value, int ndigit, char *buf); 

Description

ecvt() converts a floating-point number value to a string of ndigit EBCDIC digits and

returns a pointer to this string as its result. The output format corresponds to the %f format of printf().

The string begins with the first non-zero digit of the floating-point number, i.e. leading zeros are not included.

The decimal character and a negative sign, if any, do not form a part of the string. However, ecvt() returns the position of the decimal point and the sign in result parameters.

value is a floating-point value that is to be edited for output.

ndigit is the number of digits in the result string (calculated from the first non-zero digit of the floating-point number to be converted). If ndigit is less than the number of digits in value, the least significant digit is rounded. If ndigit is greater, zero padding is used for right justification. The accuracy of the converted number is restricted by the maximum number of significant digits that can be represented in the type double.

decpt is the pointer to an integer specifying the position of the decimal character in the result string. If *decpt is a positive number, the position of the decimal character relative to the beginning of the result string is specified. If *decpt is a negative number or 0, the decimal character is to the left of the first digit. If the integer part of value cannot be represented in full with ndigit digits, *decpt is greater than ndigit.

sign is the pointer to an integer specifying the sign of the result string. If *sign is 0, the sign is positive; if *sign is not 0: the sign is negative.

fcvt() is identical to ecvt(), except that ndigit specifies the number of digits after the decimal character.

If ndigit is less than the number of digits in value after the decimal character, the least significant digit is rounded. If ndigit is greater, zero padding is used for right justification.

gcvt() converts a floating-point number value into a string of EBCDIC digits according to the %g format of printf() and writes the prepared string to an array which is pointed to by buf. A pointer to this area is returned as the result. ndigit significant digits are generated (upper limit for ndigit is the number of significant digits which corresponds to the precision of the type double). If ndigit is less than the number of digits in value, the least significant
digit is rounded. If ndigit is greater, the string ends with the last digit that is not 0. If value represents an integer, buf is zero-padded for right justification.

In addition the string contains a minus sign if the value is < 0, and the decimal character if value is not an integer. The decimal character used is based on the current locale and is determined there by the category LC_NUMERIC. If the locale was not explicitly changed using setlocale(), the default value “POSIX“ applies. In the POSIX locale the decimal character is a period (.).

Depending on the structure of the floating-point number to be converted, the output format corresponds to

  • the %f format of printf(), or

  • the %e format of printf() (exponential / scientific notation).

ndigit is the number of digits in the result string (calculated as of the first non-zero digit from the floating-point number to be converted).

*buf is the pointer to the converted string.
The memory area pointed to by buf should be at least (ndigit + 4) bytes in size!

ecvt(), fcvt() and gcvt() are not thread-safe.

Return val.

ecvt(), fcvt():
Pointer to the converted EBCDIC string



if successful. The string is terminated with the null byte (\0).

 

gcvt():


 

*buf

if successful. The string is terminated with the null byte (\0).

Notes

An invalid parameter, such as an integer value instead of a double value, will cause the program to abort.

Portable applications should use the sprintf() function instead of ecvt(), fcvt() and gcvt().

ecvt() and fcvt(): The result is stored in an internal C data area which is overwritten with each subsequent call of one of these functions.

See also

printf(), setlocale(), sprintf(), stdlib.h.