function StrToFloat_Universal( pText : string ): Extended; const EUROPEAN_ST = ',';
AMERICAN_ST = '.'; var lformatSettings : TFormatSettings;
lFinalValue : string;
lIndx : Byte;
lIsAmerican : Boolean;
lIsEuropean : Boolean;
begin lIsAmerican := False;
lIsEuropean := False;
for lIndx := Length( pText ) - 1 downto 0 do
begin
if ( pText[ lIndx ] = AMERICAN_ST ) then
begin
lIsAmerican := True;
pText := StringReplace( pText, ',', '', [ rfIgnoreCase, rfReplaceAll ]);
Break;
end;
if ( pText[ lIndx ] = EUROPEAN_ST ) then
begin
lIsEuropean := True;
pText := StringReplace( pText, '.', '', [ rfIgnoreCase, rfReplaceAll ]); Break; end; end; GetLocaleFormatSettings( LOCALE_SYSTEM_DEFAULT, lformatSettings );
if ( lformatSettings.DecimalSeparator = EUROPEAN_ST ) then
begin
if lIsAmerican then
begin
lFinalValue := StringReplace( pText, '.', ',', [ rfIgnoreCase, rfReplaceAll ] );
end;
end;
if ( lformatSettings.DecimalSeparator = AMERICAN_ST ) then
begin
if lIsEuropean then
begin
lFinalValue := StringReplace( pText, ',', '.', [ rfIgnoreCase, rfReplaceAll ] );
end;
end;
pText := lFinalValue; Result := StrToFloat( pText, lformatSettings );
end;
procedure TForm1.Button1Click(Sender: TObject);
var
N1:Real;
Begin
N1:= StrToFloat_Universal (Edit1.Text);
N1:= N1 + StrToFloat_Universal( Edit2.text);
Label1.Caption:= FloatToStr(N1);
end;
end.