mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-24 03:39:31 +02:00
* only allow decimalseparator to be used as decimal separator in
texttofloat() and friends, rather than both '.' and decimalseparator (mantis #9126) git-svn-id: trunk@11069 -
This commit is contained in:
parent
fb3242b2f7
commit
e60e078eb5
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -9133,6 +9133,7 @@ tests/webtbs/tw9098.pp svneol=native#text/plain
|
||||
tests/webtbs/tw9107.pp svneol=native#text/plain
|
||||
tests/webtbs/tw9108.pp svneol=native#text/plain
|
||||
tests/webtbs/tw9113.pp svneol=native#text/plain
|
||||
tests/webtbs/tw9126.pp svneol=native#text/plain
|
||||
tests/webtbs/tw9128.pp svneol=native#text/plain
|
||||
tests/webtbs/tw9139.pp svneol=native#text/plain
|
||||
tests/webtbs/tw9139a.pp svneol=native#text/plain
|
||||
|
@ -1024,9 +1024,19 @@ Var
|
||||
|
||||
Begin
|
||||
S:=StrPas(Buffer);
|
||||
P:=Pos(FormatSettings.DecimalSeparator,S);
|
||||
If (P<>0) Then
|
||||
S[P] := '.';
|
||||
if (FormatSettings.DecimalSeparator<>'.') then
|
||||
begin
|
||||
{ only decimalseparator may appear in the string }
|
||||
P:=Pos('.',S);
|
||||
if (P<>0) then
|
||||
begin
|
||||
result:=false;
|
||||
exit;
|
||||
end;
|
||||
P:=Pos(FormatSettings.DecimalSeparator,S);
|
||||
If (P<>0) Then
|
||||
S[P] := '.';
|
||||
end;
|
||||
Val(trim(S),Value,E);
|
||||
Result:=(E=0);
|
||||
End;
|
||||
|
38
tests/webtbs/tw9126.pp
Normal file
38
tests/webtbs/tw9126.pp
Normal file
@ -0,0 +1,38 @@
|
||||
{$ifdef fpc}
|
||||
{$mode delphi}
|
||||
{$endif}
|
||||
|
||||
uses sysutils;
|
||||
|
||||
var
|
||||
failed : boolean;
|
||||
|
||||
procedure testconvert(s : string; shouldsucceed: boolean);
|
||||
var
|
||||
succeeded: boolean;
|
||||
begin
|
||||
succeeded:=true;
|
||||
try
|
||||
writeln(strtofloat(s));
|
||||
except
|
||||
on EConvertError do begin
|
||||
writeln('Failed to convert ', s, ' to a float value');
|
||||
succeeded := false;
|
||||
end;
|
||||
end;
|
||||
failed:=failed or (succeeded<>shouldsucceed);
|
||||
end;
|
||||
|
||||
begin
|
||||
failed := false;
|
||||
|
||||
thousandseparator := '.';
|
||||
decimalseparator := ',';
|
||||
|
||||
testconvert('1.200',false); // fails
|
||||
testconvert('1,200',true); // working
|
||||
testconvert('1.200,23',false); // fails
|
||||
testconvert('1.200.300',false); // fails
|
||||
|
||||
if (failed) then halt(1);
|
||||
end.
|
Loading…
Reference in New Issue
Block a user