_fcvt_fcvt

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

语法Syntax

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

参数Parameters

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

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

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

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

返回值Return Value

_fcvt将指针返回到的位数,字符串NULL错误。_fcvt returns a pointer to the string of digits, NULL on error.

备注Remarks

_Fcvt函数将浮点数转换为以 null 结尾的字符串。The _fcvt function converts a floating-point number to a null-terminated character string. 参数是要转换的浮点数。The value parameter is the floating-point number to be converted. _fcvt存储的位数作为字符串,并追加 null 字符 (\0)。_fcvt stores the digits of value as a string and appends a null character ('\0'). 计数参数指定要存储在小数点之后的数字个数。The count parameter specifies the number of digits to be stored after the decimal point. 多余的数字被舍入为计数放置。Excess digits are rounded off to count places. 如果有数不能超过计数位精度,该字符串则用零填充。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. 小数点和的符号的位置可以从获取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. 参数登录指向一个整数,表示的符号The parameter sign points to an integer indicating the sign of value. 整数设置为 0,如果为正数,并且设置为非零的数字如果为负。The integer is set to 0 if value is positive and is set to a nonzero number if value 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 results 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.

要求Requirements

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

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

示例Example

// 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_latof, _atof_l, _wtof, _wtof_l
_ecvt_ecvt
_gcvt_gcvt