即使 TFormatSetting 设置为 en-US,如何解决“10,000.00”不是有效的浮点值

How to solve '10,000.00' is not a valid floating point value when even TFormatSetting is set to en-US

我正在尝试从 10,000.00:

获取 Double
aProductData.BuyPriceHT := 10000;
BuyPriceHTEdit.Text := FormatFloat('#,###.#0', aProductData.BuyPriceHT, FCurrencyFormat);
aProductData.BuyPriceHT := StrToFloat(BuyPriceHTEdit.Text, FCurrencyFormat); <-- error here

其中 aProductData.BuyPriceHTDouble

FCurrencyFormat := TFormatSettings.Create('en-US'); 

注意:致那些建议使用 DecimalsInt64 类型在数据库中存储货币的好人。 我已经做了,只是它仍然困扰着我为什么它不起作用。

来自 StrToFloat 的文档:

Thousand separators and currency symbols are not allowed in the string.

一般来说,您可以使用多种不同的方式来书写数字、日期和时间,因此您不想将 字符串(文本表示)转换为[=21] =]到这样的值。

通常,您确保始终以数字形式存储和传输此类值(例如,整数、浮点数或此类值的记录),并且仅在需要时将此类值转换为文本表示形式在 GUI 中显示或写入文本文件。

如果您需要将其作为文本存储或传输,请使用严格定义的格式。然后您可以编写自己的转换器来明确解释该特定格式。