_atodbl、 _atodbl_l、 _atoldbl、 _atoldbl_l、 _atoflt _atoflt_l
將字串轉換的兩倍 (_atodbl)、 長雙精度 (_atoldbl),或浮點數 (_atoflt)。
int _atodbl(
_CRT_DOUBLE * value,
char * str
);
int _atodbl_l (
_CRT_DOUBLE * value,
char * str,
locale_t locale
);
int _atoldbl(
_LDOUBLE * value,
char * str
);
int _atoldbl_l (
_LDOUBLE * value,
char * str,
locale_t locale
);
int _atoflt(
_CRT_FLOAT * value,
char * str
);
int _atoflt_l(
_CRT_FLOAT * value,
char * str,
locale_t locale
);
參數
value
雙精算太久 double 處理,或浮動藉由將字串轉換為浮點數值時所產生值。這些值會包裝在結構中。str
要進行剖析,將轉換成浮點數值的字串。locale
若要使用地區設定。
傳回值
傳回 0,如果登錄成功。 可能的錯誤代碼是_UNDERFLOW或_OVERFLOW,已定義在標頭檔 Math.h。
備註
這些函式會將字串轉換為浮點數值。這些函式之間的差異,並atof函式家族是這些函式並不會產生浮點數的程式碼,並且因此不會造成硬體例外狀況。相反地,錯誤狀況報告為錯誤代碼。
如果字串沒有正確的解譯為浮點數值,而value設定為零,並傳回值為零。
使用這些函式的版本_l尾碼完全相同,不同之處在於它們使用傳遞中而不是目前執行緒的地區設定的地區設定參數。
需求
常式 |
所需的標頭 |
---|---|
_atodbl, _atoldbl, _atoflt _atodbl_l, _atoldbl_l, _atoflt_l |
<stdlib.h> |
範例
// crt_atodbl.c
// Uses _atodbl to convert a string to a double precision
// floating point value.
#include <stdlib.h>
#include <stdio.h>
int main()
{
char str1[256] = "3.141592654";
char abc[256] = "abc";
char oflow[256] = "1.0E+5000";
_CRT_DOUBLE dblval;
_CRT_FLOAT fltval;
int retval;
retval = _atodbl(&dblval, str1);
printf("Double value: %lf\n", dblval.x);
printf("Return value: %d\n\n", retval);
retval = _atoflt(&fltval, str1);
printf("Float value: %f\n", fltval.f);
printf("Return value: %d\n\n", retval);
// A non-floating point value: returns 0.
retval = _atoflt(&fltval, abc);
printf("Float value: %f\n", fltval.f);
printf("Return value: %d\n\n", retval);
// Overflow.
retval = _atoflt(&fltval, oflow);
printf("Float value: %f\n", fltval.f);
printf("Return value: %d\n\n", retval);
return 0;
}