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. value 参数是要转换的浮点数。The value parameter is the floating-point number to be converted. 此函数最多存储 countvalue 作为字符串,并追加空字符 ('\0')。This function stores up to count digits of value as a string and appends a null character ('\0'). 如果 value 中的数字位数超过 count,则低位数字被舍入。If the number of digits in value exceeds count, the low-order digit is rounded. 如果数字位数少于 count,则字符串使用零来填充。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. 小数点位置和 value 的符号可以在调用后从 decsign 中获取。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. sign 参数指向一个整数,表示转换后的数字的符号。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 之间的差异在于对 count 参数的解释。The difference between _ecvt and _fcvt is in the interpretation of the count parameter. _ecvtcount 解释为输出字符串中的数字总位数,而 _fcvtcount 解释为小数点后面的数字位数。_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. 如果 decsign 为 NULL,或 count 为 0,则调用无效参数处理程序,如参数验证中所述。If dec or sign is NULL, or count is 0, the invalid parameter handler is invoked, as described in Parameter Validation. 如果允许继续执行,则 errno 被设置为 EINVAL 且返回 NULL。If execution is allowed to continue, errno is set to EINVAL and NULL is returned.


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

有关更多兼容性信息,请参见“简介”中的 兼容性For more compatibility information, see Compatibility in the Introduction.


// 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_l atof, _atof_l, _wtof, _wtof_l
_fcvt _fcvt