morseus2
asked on
string to integer range error
I can't convert this string to numerical value. Is there any way to do it ?
error - '44849848974575' is not a valid integer value
........
begin
showmessage(inttostr(strto int('44849 848974575' )));
end;
error - '44849848974575' is not a valid integer value
........
begin
showmessage(inttostr(strto
end;
ASKER
There is upgraded source for both fuctions inttostr, strtoint. It does 18-digit numbers.
function strtoint2(s:string):int64;
var i,len:longint;
res:int64;
lame:array[1..30] of int64;
function exp(x,n:int64):int64;
var y:int64;
i:longint;
begin
y:=x;
for i:=1 to n-1 do
begin
y:=y*x;
end;
result:=y;
end;
begin
for i:=1 to 30 do
begin
lame[i]:=(exp(10,i)) div 10;
end;
len:=length(s); res:=0;
for i:=1 to len do
begin
res:=res+(lame[i]*strtoint (s[len+1-i ]));
end;
result:=res;
end;
function inttostr2(n:int64):string;
var i:longint;
point,help:int64;
res:string;
stop:boolean;
lame:array[1..30] of int64;
function exp(x,n:int64):int64;
var y:int64;
i:longint;
begin
y:=x;
for i:=1 to n-1 do
begin
y:=y*x;
end;
result:=y;
end;
begin
for i:=1 to 30 do
begin
lame[i]:=(exp(10,i)) div 10;
end;
stop:=false;
for i:=1 to 30 do
begin
if stop=false then
begin
if ((n / lame[i] ) >= 1) and ((n / lame[i] ) < 10) then
begin
stop:=true;
point:=i;
end;
end;
end;
res:='';
while n > 1 do
begin
res:=res+inttostr(trunc(n/ lame[point ]))[1];
help:=((trunc (n/lame[point]))*lame[poin t]);
n:=n-help;
dec(point);
end;
result:=res;
end;
function strtoint2(s:string):int64;
var i,len:longint;
res:int64;
lame:array[1..30] of int64;
function exp(x,n:int64):int64;
var y:int64;
i:longint;
begin
y:=x;
for i:=1 to n-1 do
begin
y:=y*x;
end;
result:=y;
end;
begin
for i:=1 to 30 do
begin
lame[i]:=(exp(10,i)) div 10;
end;
len:=length(s); res:=0;
for i:=1 to len do
begin
res:=res+(lame[i]*strtoint
end;
result:=res;
end;
function inttostr2(n:int64):string;
var i:longint;
point,help:int64;
res:string;
stop:boolean;
lame:array[1..30] of int64;
function exp(x,n:int64):int64;
var y:int64;
i:longint;
begin
y:=x;
for i:=1 to n-1 do
begin
y:=y*x;
end;
result:=y;
end;
begin
for i:=1 to 30 do
begin
lame[i]:=(exp(10,i)) div 10;
end;
stop:=false;
for i:=1 to 30 do
begin
if stop=false then
begin
if ((n / lame[i] ) >= 1) and ((n / lame[i] ) < 10) then
begin
stop:=true;
point:=i;
end;
end;
end;
res:='';
while n > 1 do
begin
res:=res+inttostr(trunc(n/
help:=((trunc (n/lame[point]))*lame[poin
n:=n-help;
dec(point);
end;
result:=res;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nice
ASKER
function strtoint2(s:string):cardin
var i,len,res:word;
lame:array[1..15] of cardinal;
function mocnina(a,i:word):cardinal
var b:cardinal;
x:word;
begin
b:=a;
for x:=1 to i-1 do
begin
b:=b*a;
end;
result:=b;
end;
begin
for i:=1 to 15 do // rad
begin
lame[i]:=(mocnina(10,i)) div 10;
end;
len:=length(s);
res:=0;
for i:=1 to len do
begin
res:=res+(lame[i]*strtoint
end;
result:=res;
end;