views:

536

answers:

1

hi!

I have this weird problem that a convert of a string on my machine and a production server gets different results eg:

procedure TForm1.Button1Click(Sender: TObject);
var
   s1: string;
   f1: double;
begin
   s1 := '1.234';
   f1 := StrToFloat(s1); 
end;

procedure TForm1.Button2Click(Sender: TObject);
var
   s2: string;
   f2: double;
begin
   s2 := '1,234';
   f2 := StrToFloat(s2); 
end;

Button1Click results on my WinXP machine in an '1.234' is not a valid floating point value whereas on the Win2K machine this works just fine.

Button2Click on the other end behaves on my WinXP but does result in an '1,234' is not a valid floating point value error.

Both machines have regional settings set to "German(Austria)" - any ideas as to why this is happening or at least why the regional-settings dialog does show a different decimalseparator character than the Delphi "DecimalSeparator" and "GetLocaleChar(GetThreadLocale, LOCALE_SDECIMAL, '.')?

Regards, Reinhard

+10  A: 

the DecimalSeparator variable stores the value of the Windows decimal separator as defined in the regional settings. If a decimal point appears in the String to convert with the StrToFloat function then it must match with the current DecimalSeparator value. I believe that although the regional settings match the decimal separator must be different in both systems. you can check with this code the values set in both systems.

uses
Windows;

procedure TForm1.Button3Click(Sender: TObject);
Var
StrDummy : string;
begin
 StrDummy:='Decimal Separator in Windows '+GetLocaleChar(GetThreadLocale, LOCALE_SDECIMAL, '.')+#13#10+
           'Decimal Separator in Delphi  '+DecimalSeparator;
 ShowMessage(StrDummy);

end;
RRUZ
thx, that's what I've thought too so I printed the DecimalSeparator and it showed different than what was showing in the regionalsettings than what's in "DecimalSeparator" or "GetLocaleChar(GetThreadLocale, LOCALE_SDECIMAL, '.')" Anyways, I've set and re-set the regional settings form German(Austria) to English(UK) and vice versa and you won't belive it, now erverything is OK.
pastacool
So, why haven't you marked this answer as "accepted"?
Leonardo Herrera