美文网首页
TextToFloat - C++ Builder

TextToFloat - C++ Builder

作者: 玄坴 | 来源:发表于2022-05-12 08:59 被阅读0次

C++ Builder 参考手册System::SysutilsTextToFloat


字符串转浮点数值

头文件:#include <System.SysUtils.hpp>
命名空间:System::Sysutils
函数原型:

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);

参数:

  • Buffer:字符串;
  • Value:浮点数,输出转换结果;
  • ValueType:参数 Value 的类型:
    • fvExtended:参数 Value 输出 System::Extended 类型数值;
    • fvCurrency:参数 Value 输出 System::Currency 类型数据;
  • AFormatSettings:地区格式;

返回值:

  • true:转换成功,通过参数 Value 输出转换之后的浮点类型数值;
  • false:转换失败;
  • 如果没有 AFormatSettings 参数,小数点使用全局变量 FormatSettings.DecimalSeparator,
    不同国家或地区的小数点也不同,例如:中国和美国使用小圆点 '.',法国和越南使用逗号 ',';
    如果 FormatSettings 被修改,可以用 Sysutils::GetFormatSettings(); 恢复默认值为本地格式;
  • 如果有 AFormatSettings 参数,小数点使用 AFormatSettings.DecimalSeparator;
  • 没有 AFormatSettings 参数的 CurrToStrF 函数不是线程安全的,因为使用了全局变量 FormatSettings 作为默认的地区格式;带有 AFormatSettings 参数的函数是线程安全的;
  • 参数 Buffer 为 char * 类型的函数由于 ANSI 编码原因视为过时函数,其他版本的函数为现在使用的函数。

相关:


C++ Builder 参考手册System::SysutilsTextToFloat

相关文章

网友评论

      本文标题:TextToFloat - C++ Builder

      本文链接:https://www.haomeiwen.com/subject/psidahtx.html