Solved

Converting  string to integer

Posted on 2006-06-27
14
297 Views
Last Modified: 2008-02-01
Hello experts:
I'm having problems converting  from string to integer.
Here's my code

int AccountNumberNum = 0;  
string AccountNumberWk = '1234567890123456';   //16 bytes

AccountNumberNum = Convert.ToInt32(AccountNumberWk);


It complains that " Value was either too large or too small for an int32"
Also tried long AccountNumberNum = 0;  same result
Also tried double AccountNumberNum = 0;  same result

0
Comment
Question by:lancerxe
14 Comments
 
LVL 9

Accepted Solution

by:
DrAske earned 250 total points
ID: 16997093
* System.Int32 (int)  < -2,147,483,648 to 2,147,483,647>
* System.UInt32 ( uint ) < 0 to 4,294,967,295>
* System.Int64 ( long )  <-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807>
* System.UInt64 ( ulong )< 0 to 18,446,744,073,709,551,615>

so use *long* in your task ..

long AccountNumberNum = 0;
... etc

regards, Ahmad;
 
0
 
LVL 9

Expert Comment

by:DrAske
ID: 16997101
string AccountNumberWk = '1234567890123456';   //16 bytes
use double qoutation "1234567890123456"(it's string) ..

bye ..
0
 
LVL 9

Expert Comment

by:DrAske
ID: 16997117
one more thing ..
>>AccountNumberNum = Convert.ToInt32(AccountNumberWk);
when using *long* replace Convert.ToInt32 with Convert.ToInt64(....) or
like this :
AccountNumberNum = long.Parse(AccountNumberWk);
0
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 16998419
string s="val";
int a=Convert.ToInt32(a,10);
0
 
LVL 5

Expert Comment

by:t_itanium
ID: 16998781
to declare int of 32 or 16 you can use Int32 or Int16



Int32 AccountNumberNum = 0;  
string AccountNumberWk = '1234567890123456';   //16 bytes

AccountNumberNum = Int32.Parse(AccountNumberWk);
0
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.

 
LVL 9

Expert Comment

by:DrAske
ID: 16999599
Hi *t_itanium* .. your code is Wrong ..
And what is the difference between your post and the original one ??
as we know in C# (int is alias for System.Int32) .. right?? see my first post ..

regards, Ahmad;
0
 
LVL 5

Assisted Solution

by:t_itanium
t_itanium earned 250 total points
ID: 16999827
sorry for that i should have put :

Int64 AccountNumberNum = 0;  
string AccountNumberWk = "1234567890123456";

AccountNumberNum = Int64.Parse(AccountNumberWk);

i did not realize that you explained that long and INt64 are hte same ..sorry for that..

cheers
0
 

Author Comment

by:lancerxe
ID: 17002104
Hey guys:

I used the following and it worked.

long AccountNumberNum = 0;
AccountNumberNum = Convert.ToInt64(AccountNumberWk);
I think t itanium came closest so he gets the points

thanks to everyone that responded
0
 
LVL 9

Expert Comment

by:DrAske
ID: 17002200
What???
I think I gave you the same answer ..!!
My first post I told you to use *long* ..
>>long AccountNumberNum = 0;
>> ... etc
and my third post i told you to do the following ..
>>when using *long* replace Convert.ToInt32 with Convert.ToInt64(....) or
>>like this :
>>AccountNumberNum = long.Parse(AccountNumberWk);
and don't say it's differ .. !!

nevermind ..
thanx alot ..

regards, Ahmad;
0
 
LVL 5

Expert Comment

by:t_itanium
ID: 17007011
>In 4 days, the points will be re allotted to DrAske if no one has any objections.

if you think that this is fair.. i splitting the points is much fair althoug Greg mentioned that Int64 is better since it always point to 64 int..

cheers
Tarek
0
 
LVL 5

Expert Comment

by:t_itanium
ID: 17007012
> i splitting

correction i think splitting..
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

Title # Comments Views Activity
bulid json format 3 45
Iterate a dictionnary to change values 4 53
Allow space in this pattern 2 46
Angular - break the dataset in chunks? 7 38
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

930 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

11 Experts available now in Live!

Get 1:1 Help Now