TextToFloat - C++ Builder

C++ Builder 參考手冊(cè) ? System::Sysutils ? TextToFloat


字符串轉(zhuǎn)浮點(diǎn)數(shù)值

頭文件:#include <System.SysUtils.hpp>
命名空間:System::Sysutils
函數(shù)原型:

bool __fastcall TextToFloat(System::WideChar *Buffer, void *Value, TFloatValue ValueType);
bool __fastcall TextToFloat(System::WideChar *Buffer, void *Value, TFloatValue ValueType, const TFormatSettings &AFormatSettings);
bool __fastcall TextToFloat(char *Buffer, void *Value, TFloatValue ValueType);
bool __fastcall TextToFloat(char *Buffer, void *Value, TFloatValue ValueType, const TFormatSettings &AFormatSettings);
bool __fastcall TextToFloat(const System::UnicodeString S, System::Extended &Value);
bool __fastcall TextToFloat(const System::UnicodeString S, System::Extended &Value, const TFormatSettings &AFormatSettings);
bool __fastcall TextToFloat(const System::UnicodeString S, double &Value);
bool __fastcall TextToFloat(const System::UnicodeString S, double &Value, const TFormatSettings &AFormatSettings);
bool __fastcall TextToFloat(const System::UnicodeString S, System::Currency &Value);
bool __fastcall TextToFloat(const System::UnicodeString S, System::Currency &Value, const TFormatSettings &AFormatSettings);

參數(shù):

  • Buffer:字符串;
  • Value:浮點(diǎn)數(shù),輸出轉(zhuǎn)換結(jié)果;
  • ValueType:參數(shù) Value 的類型:
    ? fvExtended:參數(shù) Value 輸出 System::Extended 類型數(shù)值;
    ? fvCurrency:參數(shù) Value 輸出 System::Currency 類型數(shù)據(jù);
  • AFormatSettings:地區(qū)格式;

返回值:

  • true:轉(zhuǎn)換成功,通過(guò)參數(shù) Value 輸出轉(zhuǎn)換之后的浮點(diǎn)類型數(shù)值;
  • false:轉(zhuǎn)換失??;
  • 如果沒(méi)有 AFormatSettings 參數(shù),小數(shù)點(diǎn)使用全局變量 FormatSettings.DecimalSeparator,
    不同國(guó)家或地區(qū)的小數(shù)點(diǎn)也不同,例如:中國(guó)和美國(guó)使用小圓點(diǎn) '.',法國(guó)和越南使用逗號(hào) ',';
    如果 FormatSettings 被修改,可以用 Sysutils::GetFormatSettings(); 恢復(fù)默認(rèn)值為本地格式;
  • 如果有 AFormatSettings 參數(shù),小數(shù)點(diǎn)使用 AFormatSettings.DecimalSeparator;
  • 沒(méi)有 AFormatSettings 參數(shù)的 CurrToStrF 函數(shù)不是線程安全的,因?yàn)槭褂昧巳肿兞?FormatSettings 作為默認(rèn)的地區(qū)格式;帶有 AFormatSettings 參數(shù)的函數(shù)是線程安全的;
  • 參數(shù) Buffer 為 char * 類型的函數(shù)由于 ANSI 編碼原因視為過(guò)時(shí)函數(shù),其他版本的函數(shù)為現(xiàn)在使用的函數(shù)。

相關(guān):


C++ Builder 參考手冊(cè) ? System::Sysutils ? TextToFloat

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容