Solved

string to integer range error

Posted on 2003-10-26
4
210 Views
Last Modified: 2010-04-05
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;

0
Comment
Question by:morseus2
  • 3
4 Comments
 

Author Comment

by:morseus2
Comment Utility
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;
0
 

Author Comment

by:morseus2
Comment Utility
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;
0
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 125 total points
Comment Utility
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...)
0
 

Author Comment

by:morseus2
Comment Utility
Nice
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now