gpt4 book ai didi

delphi xe5 StrToFloat 失败将ThousandSeparator更改为 ','

转载 作者:行者123 更新时间:2023-12-03 14:57:30 27 4
gpt4 key购买 nike

我在这里做错了什么?我只是想将格式化字符串转换为 double 型,并使用 TFormatSettings 作为参数传递给 StrToFloat。我收到以下异常:

  '3,332.1' is not a valid floating point value.  

千位分隔符和小数分隔符是 TFormatSettings 中的预期值(“,”和“.”)。

procedure TForm2.Button1Click(Sender: TObject);
var
FS: TFormatSettings;
S: String;
V: double;
begin
FS:= TFormatSettings.Create;
codesite.Send('ThousandSeparator', FS.ThousandSeparator); //correct ','
codesite.Send('DecimalSeparator', FS.DecimalSeparator); //correct '.'
S := '3,332.1';
try
V := StrToFloat(S, FS);
except on E: Exception do
ShowMessage(e.Message);
end;
CodeSite.Send('S', S);
CodeSite.Send('V', V);
end;

最佳答案

此行为是按照设计的。来自 documentation ,我强调的是:

Use StrToFloat to convert a string, S, to a floating-point value. S must consist of an optional sign (+ or -), a string of digits with an optional decimal point, and an optional mantissa. The mantissa consists of 'E' or 'e' followed by an optional sign (+ or -) and a whole number. Leading and trailing blanks are ignored.

The DecimalSeparator global variable or its TFormatSettings equivalent defines the character that is used as a decimal point. Thousand separators and currency symbols are not allowed in the string. If S does not contain a valid value, StrToFloat raises an EConvertError exception.

因此,将包含千位分隔符的字符串传递给此函数是错误的。

关于delphi xe5 StrToFloat 失败将ThousandSeparator更改为 ',',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25828219/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com