x.xxxx不是有效的浮点数。语言/本地人之间的转换 [英] x.xxxx is not a valid floating point. Converting between languages/locals
本文介绍了x.xxxx不是有效的浮点数。语言/本地人之间的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个西班牙语用户,当这样做 $
I have a spanish user who is getting an invalid floating point error
when doing this
var
S : String;
R : Real;
begin
S := '3.12345';
R := StrToFloat(S); //- Exception here.
原因是他的位置使用,
用于小数位!
如何安全地将上面的字符串转换为用户的浮点数,而不会被轰炸。
The reason for this is that his location uses ,
for the decimal place!
How can I safely convert the string above to a float for the user without it bombing out.
推荐答案
滚动您自己的StrToFloat版本
Roll your own version of StrToFloat
function StrToFloat_UK(const AStr: string): Float;
var
FS: TFormatSettings;
begin
FS.Create('en-UK');
Result:= StrToFloat(AStr, FS):
end;
并使用此代替StrToFloat。
And use this in place of StrToFloat.
这篇关于x.xxxx不是有效的浮点数。语言/本地人之间的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文