Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# string to integer range error

Posted on 2003-10-26
Medium Priority
218 Views
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
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
• 3

Author Comment

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

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

Wim ten Brink earned 500 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

ID: 9629633
Nice
0

## Featured Post

Question has a verified solution.

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

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…
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…
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
###### Suggested Courses
Course of the Month9 days, 9 hours left to enroll