We help IT Professionals succeed at work.

converting string to integer

n_chai
n_chai asked
on
Medium Priority
559 Views
Last Modified: 2010-04-04
How do i convert a string to integer which is to large and exceed 2147483647 in delphi 3 ?

Thank you.      
Comment
Watch Question

Commented:
Why not convert it to double/extended?

You know, even you can convert it to an "integer", it will result in no use because it cannot participate any calculation with other integers due to exceeding the limit of this type.

Commented:
If you've Delphi4 you can use StrToInt64 and you'll get an 8 byte integer (int64) as a result.

Regards, Madshi.

Commented:
Otherwise just StrToInt(); will do

Bink
CERTIFIED EXPERT

Commented:
 ... or StrToIntDef() and avoid having to handle your own exceptions.
4 byte signed integers (D3 Integer type) can't represent numbers greater than 2^31-1, that's why StrToInt fails.
There is no 4 byte unsigned type in D3, it could have been Cardinal or DWORD, but they are both declared as Integer (I think). At least then you could have got to 2^32-1.

As dwwang says, use Extended remembering that they don't represent integers very well.

What's the nature of your app any, and why the big numbers?
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:
You must use 8 or more bytes for storing lage values.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.