Solved

string to integer range error

Posted on 2003-10-26
4
215 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

617 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