- CurrToStr - C++ Builder
- C++ Builder 的字符串类型、字符类型、字符编码
- TInterfacedPersistent::AfterCons
- TInterfacedPersistent::QueryInte
- TInterfacedPersistent::~TInterfa
- TInterfacedPersistent::TInterfac
- TThread::NameThreadForDebugging
- TThread::Suspended - C++ Builder
- TThread::Terminate - C++ Builder
- TInterfacedObject - C++ Builder
C++ Builder 参考手册 ➙ System::Sysutils ➙ CurrToStr
货币型数值转字符串
头文件:#include <System.SysUtils.hpp>
命名空间:System::Sysutils
函数原型:
System::UnicodeString __fastcall CurrToStr(System::Currency Value);
System::UnicodeString __fastcall CurrToStr(System::Currency Value, const TFormatSettings &AFormatSettings);
参数:
- Value:货币型变量;
- AFormatSettings:地区格式;
返回值:
- 参数 Value 转为字符串;
- 地区格式:这个函数使用了地区格式的 DecimalSeparator 作为小数点,不同的地区可能会使用不同的字符当做小数点,中国和大多数国家一样使用小圆点作为小数点,但是有的国家 - 例如法国:使用逗号当做小数点,如果程序在法国的电脑上运行,默认情况所有的小数点都会使用逗号的,包括浮点数,不仅仅是货币型,程序国际化时要特别注意;
- 如果没有 AFormatSettings 参数,使用当前地区格式;
- 如果有 AFormatSettings 参数,使用这个参数的格式,并且使用这个参数可以随意设定一个字符当做小数点;
- 可以使用全局变量 System::Sysutils::FormatSettings 修改默认的格式;
- 只有一个 Value 参数的 CurrToStr 函数不是线程安全的,因为使用了全局变量作为默认的地区格式;带有 AFormatSettings 参数的函数是线程安全的。
例:把 1234.56 转为字符串:1.使用默认的格式、2.使用法国格式、3.使用自定义的用 * 当做小数点的格式
void __fastcall TForm1::Button1Click(TObject *Sender)
{
System::Currency Val = 1234.56;
Memo1->Lines->Add(Sysutils::CurrToStr(Val));
Memo1->Lines->Add(Sysutils::CurrToStr(Val, TFormatSettings::Create(L"fr_FR")));
TFormatSettings fs = TFormatSettings::Create();
fs.DecimalSeparator = L'*';
Memo1->Lines->Add(Sysutils::CurrToStr(Val, fs));
}
运行结果:
运行结果相关:
- System::Sysutils::FormatSettings
- System::Sysutils::TFormatSettings
- System::Sysutils::StrToBool
- System::Sysutils::StrToBoolDef
- System::Sysutils::TryStrToBool
- System::Sysutils::BoolToStr
- System::Sysutils::CurrToStr
- System::Sysutils::CurrToStrF
- System::Sysutils::DateTimeToStr
- System::Sysutils::DateTimeToString
- System::Sysutils::DateToStr
- System::Sysutils::FloatToStr
- System::Sysutils::FloatToStrF
- 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 参考手册 ➙ System::Sysutils ➙ CurrToStr
网友评论