将转换double数字的字符串。Converts a double number to a string. 提供此函数的更安全的版本;请参阅 _ecvt_sA more secure version of this function is available; see _ecvt_s.


char *_ecvt(
   double value,
   int count,
   int *dec,
   int *sign


要转换的数字。Number to be converted.

存储的数字位数。Number of digits stored.

存储的十进制点位置。Stored decimal-point position.

转换后的数字的符号。Sign of the converted number.

返回值Return Value

_ecvt返回一个指向字符串的数字;NULL是否发生错误。_ecvt returns a pointer to the string of digits; NULL if an error occurred.


_Ecvt函数将浮点数转换为字符字符串。The _ecvt function converts a floating-point number to a character string. 参数是要转换的浮点数。The value parameter is the floating-point number to be converted. 此函数最多存储计数位数作为一个字符串,并追加 null 字符 (\0)。This function stores up to count digits of value as a string and appends a null character ('\0'). 如果中的数字个数超过计数,低位数字舍入。If the number of digits in value exceeds count, the low-order digit is rounded. 如果少于计数用零填充数字字符串。If there are fewer than count digits, the string is padded with zeros.

返回的总位数 _ecvt将不会超过 _CVTBUFSIZEThe total number of digits returned by _ecvt will not exceed _CVTBUFSIZE.

字符串中仅存储位数。Only digits are stored in the string. 小数点和的符号的位置可从此dec登录后调用。The position of the decimal point and the sign of value can be obtained from dec and sign after the call. Dec参数指向整数值提供相对于字符串开头的小数点的位置。The dec parameter points to an integer value giving the position of the decimal point with respect to the beginning of the string. 0 或负整数值表示小数点位于第一个数字的左侧。A 0 or negative integer value indicates that the decimal point lies to the left of the first digit. 登录参数指向一个整数,指示转换后的数字的符号。The sign parameter points to an integer that indicates the sign of the converted number. 如果整数值为 0,则数值为正值。If the integer value is 0, the number is positive. 否认,数值为负值。Otherwise, the number is negative.

之间的差异 _ecvt_fcvt中的解释计数参数。The difference between _ecvt and _fcvt is in the interpretation of the count parameter. _ecvt解释计数输出字符串中的位数总数而 _fcvt解释计数后的位数小数点。_ecvt interprets count as the total number of digits in the output string, whereas _fcvt interprets count as the number of digits after the decimal point.

_ecvt_fcvt使用单个静态分配的缓冲区用于转换。_ecvt and _fcvt use a single statically allocated buffer for the conversion. 每次调用这些例程都会破坏上一次调用的结果。Each call to one of these routines destroys the result of the previous call.

此函数验证其参数。This function validates its parameters. 如果dec登录NULL,或者计数为 0,则调用无效参数处理程序,如中所述参数验证If dec or sign is NULL, or count is 0, the invalid parameter handler is invoked, as described in Parameter Validation. 如果允许执行继续,则errno设置为EINVALNULL返回。If execution is allowed to continue, errno is set to EINVAL and NULL is returned.


函数Function 必需的标头Required header
_ecvt_ecvt <stdlib.h><stdlib.h>

有关更多兼容性信息,请参阅 兼容性For more compatibility information, see Compatibility.


// crt_ecvt.c
// compile with: /W3
// This program uses _ecvt to convert a
// floating-point number to a character string.

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

int main( void )
   int     decimal,   sign;
   char    *buffer;
   int     precision = 10;
   double  source = 3.1415926535;

   buffer = _ecvt( source, precision, &decimal, &sign ); // C4996
   // Note: _ecvt is deprecated; consider using _ecvt_s instead
   printf( "source: %2.10f   buffer: '%s'  decimal: %d  sign: %d\n",
           source, buffer, decimal, sign );
source: 3.1415926535   buffer: '3141592654'  decimal: 1  sign: 0

请参阅See also

数据转换Data Conversion
浮点支持Floating-Point Support
atof、_atof_l、_wtof、_wtof_latof, _atof_l, _wtof, _wtof_l