I have a few simple lines of code:
var
vRecordValue:Double;
begin
vRecordValue:= someVariant;
Where someVariant is a string (type 256).
On a production system we have a variant of '23.4' and vRecordValue becomes 234. I can only reproduce this is my system separator is ','. In our production system this was the case but we have changed the setting and still see this occurring. It is interesting to note that we cannot reproduce this at all except in debug mode (no idea what the relationship is here), and by doing a simple test.
I fixed this with an explicit conversion:
vRecordValue:= StrToFloatDef(VarToStrDef(someVariant, '0'), 0);
Questions:
Thanks,
Wayne.
It is your regional settings
I've made this samall demo applikation inorder for testing it:
procedure TForm60.FormCreate(Sender: TObject);
var
vRecordValue: Double;
sRecordValue: Variant;
begin
sRecordValue:= '23.4';
vRecordValue:= StrToFloatDef(VarToStrDef(sRecordValue, '0'), 0);
ShowMessage(FloatToStr(vRecordValue));
sRecordValue:= '23,4';
vRecordValue:= StrToFloatDef(VarToStrDef(sRecordValue, '0'), 0);
ShowMessage(FloatToStr(vRecordValue));
end;
In Denmark (Where I live) the we use , as decimal seperator, so the last one gives me the correct result