Browse Source

* Make strtoint more Delphi/FPC compatible: floats are rejected

michael 5 years ago
parent
commit
b5e238ec57
1 changed files with 6 additions and 0 deletions
  1. 6 0
      packages/rtl/sysutils.pas

+ 6 - 0
packages/rtl/sysutils.pas

@@ -4419,11 +4419,17 @@ Var
 
 
 begin
 begin
   N:=S;
   N:=S;
+  // Javascript Parseint allows 1.0 or 1E0 to be an integer, so we must check for this to get the same behaviour as FPC/Delphi.
+  if (Pos(DecimalSeparator,N)<>0) or (Pos('.',N)<>0) then
+    exit(False);
   case Copy(N,1,1) of
   case Copy(N,1,1) of
   '$': Radix:=16;
   '$': Radix:=16;
   '&': Radix:=8;
   '&': Radix:=8;
   '%': Radix:=2;
   '%': Radix:=2;
   end;
   end;
+  // Check for E after we know radix
+  if (Radix<>16) and (Pos('e',LowerCase(N))<>0) then
+    exit(False);
   If Radix<>10 then
   If Radix<>10 then
     Delete(N,1,1);
     Delete(N,1,1);
   J:=parseInt(N,Radix);
   J:=parseInt(N,Radix);