# 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(strtoint('44849848974575' )));

end;

###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Author Commented:
LoL i made it myself >

function strtoint2(s:string):cardinal;
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(s[len+1-i]));
end;

result:=res;
end;
Author Commented:
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[point]);
n:=n-help;
dec(point);
end;
result:=res;
end;
Self-employed developerCommented:
Use StrToInt64 instead. The number you're trying to convert just doesn't fit in the 4 bytes an integer can contain. Notice that StrToInt('2147483647') will go fine while StrToInt('2147483648') raises an exception. With StrToInt64 your numbers can be about 19 in length. For bigger numbers you can also use StrToFloat() which technically has no limit. (Unless your string value has several hundreds of numbers...)

Experts Exchange Solution brought to you by