Delphi 5 - StrToFloat Results Differ on WinXP and Win2K

I have this strange problem that string conversion on my machine and production server gets different results, for example:

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 computer to "1.234" is not a valid floating point value, but on Win2K it works fine.

Button2Click on the other end to behave on my WinXP, but leads to the fact that "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 shows a different decimalseparator than Delphi "DecimalSeparator" and "GetLocaleChar (GetThreadLocale, LOCALE_SDECIMAL , '.')?

Regards, Reinhard

+4
source share
1 answer

the DecimalSeparator variable stores the Windows decimal separator value as defined in the regional settings. If the decimal point appears in String for conversion using the StrToFloat function, it must match the current DecimalSeparator value. I believe that although the regional settings are the same, the decimal separator should be different on both systems. with this code you can check the values ​​set on 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; 
+12
source

All Articles