将浮点数转换为字符串。Converts a floating-point number to a string. 提供此函数的更安全的版本;请参阅 _fcvt_sA more secure version of this function is available; see _fcvt_s.


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


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

小数点后面的数字位数。Number of digits after the decimal point.

指向存储的小数点位置的指针。Pointer to the stored decimal-point position.

指向存储的符号指示符的指针。Pointer to the stored sign indicator.

返回值Return Value

_fcvt 返回指向数字字符串的指针;如果发生错误,则为 NULL。_fcvt returns a pointer to the string of digits, NULL on error.


_fcvt 函数将浮点数转换为以 null 结尾的字符串。The _fcvt function converts a floating-point number to a null-terminated character string. value 参数是要转换的浮点数。The value parameter is the floating-point number to be converted. _fcvtvalue 的位数存储为字符串,并追加一个空字符 ('\0')。_fcvt stores the digits of value as a string and appends a null character ('\0'). count 参数指定此小数点后要存储的数字位数。The count parameter specifies the number of digits to be stored after the decimal point. 多余的位数被舍入到 count 位置。Excess digits are rounded off to count places. 如果小于精确到 count 的位数,则字符串使用零填充。If there are fewer than count digits of precision, the string is padded with zeros.

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

字符串中仅存储位数。Only digits are stored in the string. 小数点位置和 value 的符号可以在调用后从 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; this integer value gives the position of the decimal point with respect to the beginning of the string. 零或负整数值表示小数点位于第一个数字的左侧。A zero or negative integer value indicates that the decimal point lies to the left of the first digit. 参数 sign 指向一个整数值,表示 value 的符号。The parameter sign points to an integer indicating the sign of value. 如果 value 为正数,则整数设置为 0,如果 value 为负数,则整数设置为非零数。The integer is set to 0 if value is positive and is set to a nonzero number if value 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 results 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
_fcvt <stdlib.h><stdlib.h>

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


// crt_fcvt.c  
// compile with: /W3  
// This program converts the constant  
// 3.1415926535 to a string and sets the pointer  
// buffer to point to that string.  

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

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

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

请参阅See Also

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