將字串轉換為長雙精確度浮點數值。
語法
long double strtold(
const char *strSource,
char **endptr
);
long double _strtold_l(
const char *strSource,
char **endptr,
_locale_t locale
);
long double wcstold(
const wchar_t *strSource,
wchar_t **endptr
);
long double wcstold_l(
const wchar_t *strSource,
wchar_t **endptr,
_locale_t locale
);
參數
strSource
以 Null 終止的待轉換字串。
endptr
停止掃描的字元指標。
locale
要使用的地區設定。
傳回值
strtold 會傳回浮點數的值做為 long double,但表示法會造成溢位的情況除外,在此情況下,函式會傳回 +/-HUGE_VALL。 的 HUGE_VALL 正負號符合無法表示之值的正負號。 如果沒有任何轉換可執行,strtold 會傳回 0,否則會發生反向溢位。
wcstold 傳回類似 strtold 的值。 針對這兩個函式,errno如果發生溢位或下溢,而且叫用無效的參數處理程式,如參數驗證中所述, 會設定ERANGE為 。
如需傳回碼的詳細資訊,請參閱errno、 _doserrno_sys_errlist和 _sys_nerr。
備註
每個函式都會將輸入字串 strSource 轉換成 long double。 函 strtold 式會停止在無法辨識為數位一部分的第一個字元讀取字串 strSource 。 這可能是終止的 Null 字元。 strtold 的寬字元版本是 wcstold,其 strSource 引數是寬字元字串。 否則,這些函式的行為相同。
根據預設,此函式的全域狀態會限定於應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。
一般文字常式對應
| TCHAR.H 常式 | _UNICODE 和 _MBCS 未定義 |
_MBCS 已定義 |
_UNICODE 已定義 |
|---|---|---|---|
_tcstold |
strtold |
strtold |
wcstold |
_tcstold_l |
_strtold_l |
_strtold_l |
_wcstold_l |
目前地區設定的 LC_NUMERIC 類別設定會決定 strSource 中的基底字元辨識。 如需詳細資訊,請參閱 setlocale和 _wsetlocale。 沒有 _l 尾碼的函式使用目前的地區設定,而 _strtold_l 和 _wcstold_l 與 _strtold 和 _wcstold 相同,只不過它們改用傳入的地區設定。 如需詳細資訊,請參閱 Locale。
如果 endptr 不是 NULL,則會將停止掃描的字元指標儲存在 所 endptr指向的位置。 如果不能執行任何轉換 (找不到任何有效的數字或指定了無效的基底),則 strSource 的值會儲存在 endptr 所指的位置。
strtold 需要 strSource 指向格式如下的字串︰
[
whitespace][sign][][digits.digits][{deD| |E| }[sign]]digits
whitespace 包含可忽略的空格及定位字元;sign 是加號 (+) 或減號 (-);而且 digits 是一或多個十進位數字。 如果基底字元前沒有任何數字,則在基底字元後至少必須要有一個數字。 小數位數的後面會接著包含簡介字母 (d、D、e 或 E) 的指數以及選擇性的帶正負號整數。 如果沒有出現指數部分或基數位元,則會假設基數位元會遵循字串中的最後一個數位。 不符合此表單的第一個字元會停止掃描。
需求
| 常式 | 必要的標頭 |
|---|---|
strtold, _strtold_l |
<stdlib.h> |
wcstold, _wcstold_l |
<stdlib.h> 或 <wchar.h> |
如需相容性詳細資訊,請參閱相容性。
範例
// crt_strtold.c
// Build with: cl /W4 /Tc crt_strtold.c
// This program uses strtold to convert a
// string to a long double-precision value.
#include <stdlib.h>
#include <stdio.h>
int main( void )
{
char *string;
char *stopstring;
long double x;
string = "3.1415926535898This stopped it";
x = strtold(string, &stopstring);
printf("string = %s\n", string);
printf(" strtold = %.13Lf\n", x);
printf(" Stopped scan at: %s\n\n", stopstring);
}
string = 3.1415926535898This stopped it
strtold = 3.1415926535898
Stopped scan at: This stopped it
另請參閱
資料轉換
數學與浮點支援
多位元組字元序列的解譯
地區設定
字串到數值函式
strtod、 、 _strtod_l、 wcstod_wcstod_l
strtol、 、 wcstol、 _strtol_l_wcstol_l
strtoul、 、 _strtoul_l、 wcstoul_wcstoul_l
atof、 、 _atof_l、 _wtof_wtof_l
localeconv
_create_locale, _wcreate_locale
_free_locale