Solved

string to integer range error

Posted on 2003-10-26
4
211 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
ID: 9624066
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
ID: 9624251
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
ID: 9627479
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
ID: 9629633
Nice
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

929 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

8 Experts available now in Live!

Get 1:1 Help Now