FloatToStr - C++ Builder

C++ Builder 參考手冊 ? System::Sysutils ? FloatToStr


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

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

System::UnicodeString __fastcall FloatToStr(System::Extended Value);
System::UnicodeString __fastcall FloatToStr(System::Extended Value, const TFormatSettings &AFormatSettings);

參數(shù):

  • Value:浮點型變量;
  • AFormatSettings:地區(qū)格式;

返回值:

  • 參數(shù) Value 轉(zhuǎn)為字符串;
  • 地區(qū)格式:這個函數(shù)使用了地區(qū)格式的 DecimalSeparator 作為小數(shù)點,不同的地區(qū)可能會使用不同的字符當(dāng)做小數(shù)點,中國和大多數(shù)國家一樣使用小圓點作為小數(shù)點,但是有的國家 - 例如法國:使用逗號當(dāng)做小數(shù)點,如果程序在法國的電腦上運行,默認(rèn)情況所有的小數(shù)點都會使用逗號的,包括浮點數(shù)和貨幣型,程序國際化時要特別注意;
  • 如果沒有 AFormatSettings 參數(shù),使用當(dāng)前地區(qū)格式;
  • 如果有 AFormatSettings 參數(shù),使用這個參數(shù)的格式,并且使用這個參數(shù)可以隨意設(shè)定一個字符當(dāng)做小數(shù)點;
  • 可以使用全局變量 System::Sysutils::FormatSettings 修改默認(rèn)的格式;
  • 只有一個 Value 參數(shù)的函數(shù)不是線程安全的,因為使用了全局變量作為默認(rèn)的地區(qū)格式;帶有 AFormatSettings 參數(shù)的函數(shù)是線程安全的。

例:分別用當(dāng)前地區(qū)格式、法國格式和自定義格式輸出浮點數(shù) 123.456789

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    double Val = 123.456789;

    Memo1->Lines->Add(Sysutils::FloatToStr(Val));
    Memo1->Lines->Add(Sysutils::FloatToStr(Val, TFormatSettings::Create(L"fr_FR")));

    TFormatSettings fs = TFormatSettings::Create();
    fs.DecimalSeparator = L'*';
    Memo1->Lines->Add(Sysutils::FloatToStr(Val, fs));
}

運行結(jié)果:

運行結(jié)果

相關(guān):

  • System::Sysutils::FormatFloat
  • System::Sysutils::FloatToStr
  • System::Sysutils::FloatToStrF
  • System::Sysutils::CurrToStr
  • System::Sysutils::CurrToStrF
  • 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
  • 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 參考手冊 ? System::Sysutils ? FloatToStr

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

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

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