FloatToText - C++ Builder

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


字符串轉(zhuǎn)為字符串,按照參數(shù)給定的格式

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

int __fastcall FloatToText(
    System::WideChar * BufferArg,
    const void *Value,
    TFloatValue ValueType,
    TFloatFormat Format,
    int Precision,
    int Digits);
int __fastcall FloatToText(char * BufferArg,
    const void *Value,
    TFloatValue ValueType,
    TFloatFormat Format,
    int Precision,
    int Digits);
int __fastcall FloatToText(
    System::WideChar * BufferArg,
    const void *Value,
    TFloatValue ValueType,
    TFloatFormat Format,
    int Precision,
    int Digits,
    const TFormatSettings &AFormatSettings);
int __fastcall FloatToText(
    char * BufferArg,
    const void *Value,
    TFloatValue ValueType,
    TFloatFormat Format,
    int Precision,
    int Digits,
    const TFormatSettings &AFormatSettings);

參數(shù):

  • BufferArg:用于返回生成的字符串;
  • Value:需要分解的浮點(diǎn)數(shù),System::Currency 或者 System::Extended 類型的變量地址;
  • ValueType:指定參數(shù) Value 的類型:
    ? fvExtended:參數(shù) Value 是 System::Extended 類型的;
    ? fvCurrency:參數(shù) Value 是 System::Currency 類型的;
  • Format:浮點(diǎn)數(shù)格式:
    ? ffGeneral:生成盡可能短的字符串,忽略 Digits 參數(shù);
    ? ffExponent:使用科學(xué)計(jì)數(shù)法,Digits 為指數(shù)的位數(shù),不是小數(shù)點(diǎn)后保留的位數(shù);
    ? ffFixed:小數(shù)點(diǎn)后保留 Digits 位;
    ? ffNumber:小數(shù)點(diǎn)后保留 Digits 位,并且整數(shù)部使用千位分隔符;
    ? ffCurrency:使用貨幣型字符串,小數(shù)點(diǎn)后保留 Digits 位;
  • Precision:精度,保留有效數(shù)字的位數(shù);
  • Digits:根據(jù) Format 參數(shù)使用;
  • AFormatSettings:地區(qū)格式;

返回值:

  • 函數(shù)返回生成的字符串的長(zhǎng)度,生成的字符串通過(guò)參數(shù) BufferArg 返回,
    ? 文檔并沒(méi)有說(shuō)明 BufferArg 具體需要的字節(jié)數(shù),在調(diào)用函數(shù)之前必須已經(jīng)分配足夠的內(nèi)存,可以根據(jù)參數(shù)估計(jì)或分配多一點(diǎn)內(nèi)存 (比如 100 個(gè)字符長(zhǎng)度);
    ? 通過(guò)參數(shù) BufferArg 返回的字符串沒(méi)有結(jié)束符,根據(jù)源碼的使用情況分析,這個(gè)函數(shù)用于連續(xù)輸出字符到緩存,這樣做可以提高效率,不要忘記在使用生成的字符串之前要在字符串長(zhǎng)度位置加一個(gè)結(jié)束符;
  • char * 類型的 BufferArg 參數(shù)的函數(shù)為過(guò)時(shí)的 ANSI 版本的函數(shù),直接使用時(shí)可能有警告或報(bào)錯(cuò),已經(jīng)移動(dòng)到 System.AnsiStrings.hpp 頭文件里面了;
  • 其他描述請(qǐng)參考 FloatToStrF

例:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    System::WideChar Buffer[100];
    System::Extended Value = -1234.56789;
    int n = FloatToText(Buffer, &Value, fvExtended, ffNumber, 8, 3);
    Buffer[n] = 0;
    Memo1->Lines->Add(Buffer);
}

運(yùn)行結(jié)果:

運(yùn)行結(jié)果

相關(guān):

  • System::Sysutils::FloatToStr
  • System::Sysutils::FloatToStrF
  • System::Sysutils::FloatToText
  • System::Sysutils::FloatToTextFmt
  • System::Sysutils::FloatToDecimal
  • System::Sysutils::FloatToCurr
  • System::Sysutils::TryFloatToCurr
  • System::Sysutils::TextToFloat
  • System::Sysutils::StrToFloat
  • System::Sysutils::StrToFloatDef
  • System::Sysutils::TryStrToFloat
  • System::Sysutils::StrToCurr
  • System::Sysutils::StrToCurrDef
  • System::Sysutils::TryStrToCurr
  • System::Sysutils::CurrToStr
  • System::Sysutils::CurrToStrF
  • System::Sysutils::FormatFloat
  • System::Sysutils::FormatCurr
  • System::Sysutils::TFloatRec
  • System::Sysutils::TFloatValue
  • System::Sysutils::FormatSettings
  • System::Sysutils::TFormatSettings
  • System::Sysutils::StrToBool
  • System::Sysutils::StrToBoolDef
  • System::Sysutils::TryStrToBool
  • System::Sysutils::BoolToStr
  • System::Sysutils::DateTimeToStr
  • System::Sysutils::DateTimeToString
  • System::Sysutils::DateToStr
  • System::Sysutils::GUIDToString
  • System::Sysutils::IntToStr
  • System::Sysutils::IntToHex
  • System::Sysutils::TimeToStr
  • System::Sysutils::UIntToStr
  • System::Sysutils
  • System::Currency
  • System
  • std::itoa, std::_itoa, std::_itot, std::_itow
  • std::ltoa, std::_ltoa, std::_ltot, std::_ltow
  • std::ultoa, std::_ultoa, std::_ultot, std::_ultow
  • std::_i64toa, std::_i64tot, std::_i64tow
  • std::_ui64toa, std::_ui64tot, std::_ui64tow
  • std::ecvt, std::_ecvt
  • std::fcvt, std::_fcvt
  • std::gcvt, std::_gcvt
  • <cstdlib>

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

?著作權(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)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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