C++ Builder 參考手冊(cè) ? System::Sysutils ? StrToCurr
字符串轉(zhuǎn)貨幣類型數(shù)值
頭文件:#include <System.SysUtils.hpp>
命名空間:System::Sysutils
函數(shù)原型:
System::Currency __fastcall StrToCurr(const System::UnicodeString S);
System::Currency __fastcall StrToCurr(const System::UnicodeString S, const TFormatSettings &AFormatSettings);
參數(shù):
- S:字符串;
- AFormatSettings:地區(qū)格式;
返回值:
- 貨幣型數(shù)值,如果轉(zhuǎn)換失敗,拋出 EConvertError 異常;
- 函數(shù) StrToCurr、StrToCurrDef 和 TryStrToCurr 的區(qū)別:
? StrToCurr 轉(zhuǎn)換失敗拋出異常;
? StrToCurrDef 轉(zhuǎn)換失敗返回默認(rèn)值;
? TryStrToCurr 轉(zhuǎn)換結(jié)果通過(guò)參數(shù)返回,函數(shù)返回值返回是否轉(zhuǎn)換成功; - 地區(qū)格式:這個(gè)函數(shù)使用了地區(qū)格式的 DecimalSeparator 成員作為小數(shù)點(diǎn),中國(guó)和大多數(shù)國(guó)家一樣使用小圓點(diǎn)作為小數(shù)點(diǎn),但是有的國(guó)家 - 例如法國(guó):使用逗號(hào)當(dāng)做小數(shù)點(diǎn),如果程序在法國(guó)和越南等國(guó)家的電腦上運(yùn)行,默認(rèn)情況所有的小數(shù)點(diǎn)都會(huì)使用逗號(hào),包括浮點(diǎn)數(shù),不僅僅是貨幣型,程序國(guó)際化時(shí)要特別注意;
- 如果沒(méi)有 AFormatSettings 參數(shù),使用全局變量 FormatSettings 作為地區(qū)格式,可以通過(guò)修改這個(gè)全局變量來(lái)修改默認(rèn)的格式,使用函數(shù) GetFormatSettings 讓這個(gè)全局變量恢復(fù)默認(rèn)格式為當(dāng)前地區(qū)格式;
- 如果有 AFormatSettings 參數(shù),使用這個(gè)參數(shù)的格式,并且使用這個(gè)參數(shù)可以隨意設(shè)定一個(gè)字符當(dāng)做小數(shù)點(diǎn);
- 沒(méi)有 AFormatSettings 參數(shù)的 CurrToStrF 函數(shù)不是線程安全的,因?yàn)槭褂昧巳肿兞?FormatSettings 作為默認(rèn)的地區(qū)格式;帶有 AFormatSettings 參數(shù)的函數(shù)是線程安全的。
例:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Memo1->Lines->Add(StrToCurr(L"10" ));
Memo1->Lines->Add(StrToCurr(L"-1.5" ));
Memo1->Lines->Add(StrToCurr(L"12.345"));
TFormatSettings fs = TFormatSettings::Create(L"fr_FR"); // 法國(guó)
// Memo1->Lines->Add(StrToCurr(L"3.14", fs)); // 法國(guó)不能用小圓點(diǎn) . 作小數(shù)點(diǎn)
Memo1->Lines->Add(StrToCurr(L"3,14", fs)); // 法國(guó)必須用逗號(hào) , 作小數(shù)點(diǎn)
}
運(yùn)行結(jié)果:

運(yùn)行結(jié)果
相關(guān):
- System::Sysutils::CurrToStr
- System::Sysutils::CurrToStrF
- System::Sysutils::StrToBool
- System::Sysutils::StrToBoolDef
- System::Sysutils::StrToCurr
- System::Sysutils::StrToCurrDef
- System::Sysutils::StrToDate
- System::Sysutils::StrToDateDef
- System::Sysutils::StrToDateTime
- System::Sysutils::StrToDateTimeDef
- System::Sysutils::StrToFloat
- System::Sysutils::StrToFloatDef
- System::Sysutils::StrToInt
- System::Sysutils::StrToIntDef
- System::Sysutils::StrToInt64
- System::Sysutils::StrToInt64Def
- System::Sysutils::StrToTime
- System::Sysutils::StrToTimeDef
- System::Sysutils::StrToUInt
- System::Sysutils::StrToUIntDef
- System::Sysutils::StrToUInt64
- System::Sysutils::StrToUInt64Def
- System::Sysutils::TryStrToBool
- System::Sysutils::TryStrToCurr
- System::Sysutils::TryStrToDate
- System::Sysutils::TryStrToDateTime
- System::Sysutils::TryStrToFloat
- System::Sysutils::TryStrToInt
- System::Sysutils::TryStrToInt64
- System::Sysutils::TryStrToTime
- System::Sysutils::TryStrToUInt
- System::Sysutils::TryStrToUInt64
- System::Sysutils
- std::atof, std::_ttof, std::_wtof
- std::_atold, std::_ttold, std::_wtold
- std::atoi, std::_ttoi, std::_wtoi
- std::atol, std::_ttol, std::_wtol
- std::atoll, std::_ttoll, std::_wtoll
- std::_atoi64, std::_ttoi64, std::_wtoi64
- std::strtof, std::_tcstof, std::wcstof
- std::strtod, std::_tcstod, std::wcstod
- std::strtold, std::wcstold, std::_strtold, std::_tcstold, std::_wcstold
- std::strtol, std::_tcstol, std::wcstol
- std::strtoll, std::_tcstoll, std::wcstoll
- std::strtoul, std::_tcstoul, std::wcstoul
- std::strtoull, std::_tcstoull, std::wcstoull
- <cstdlib>
C++ Builder 參考手冊(cè) ? System::Sysutils ? StrToCurr