How to convert long string to number?

Hello, I have 34 long string, how to convert it to long number ?

thanks :slight_smile:


How about like this?

If there are Alphas or Specials it will throw an error so keep that in mind.

to get around error you could use these examples:


or replace the Alphas
CLng(System.Text.RegularExpressions.Regex.Replace(text, “[^0-9]”, “”))



Thanks, but it doesn’t work…
“Value was either too large or too small for a Decimal”

Change CLng or ToLong to CDbl or ToDouble

Longs are integers so you might need to use Double instead to account for decimals.

34 digits is quite too much for an integer type: Long can only have a value up to 9,223,372,036,854,775,807, being 19 digits. You will have to work with floating point numbers (e.g. Double) and suffer a loss of precision, or with something like BigInteger.

1 Like

This is my string “249041911436190623612713252128”
Using windows calculator → scientific mode
249041911436190623612713252128 mod 97 = 1
and that’s fine

CDbl gives me 24 :confused:

1 Like

Try BigInteger



BigInteger solved the problem :slight_smile: thanks :slight_smile:

Hello Vaidya,

May I Know What Code You Have taken in Variable Val(BigInteger.Parse…) May I Know the Code

Please I’m a Learner… Done with the Course


If you are asking about below part, it is BigInteger.Parse(strval)


1 Like

Thank You Vaidya,

Really So Nice of You. Recently I done my Course, Going to Learn real time cases by forum…

if it is possible could you please help me with some real time cases Pleaseeeeee


I learned a long time ago that there was Integer and Long types. So it was just CInt() or CLng()
… C for convert

I don’t know if there is a difference but that’s what I use. And, it’s usually a good idea to use Long for Invoice numbers, etc.

Hi @ClaytonM,

Cint - Returns the Int32
CLng- Returns the Int64

The only main difference is the value range.


1 Like

@claytonm just to note your if would not work because integerstring.trim is not of the same type as CLNG output :S so you probably want to write “Nothing” instead

Thanks for the info @balupad14
I meant, I didn’t know if there was a difference between using BigInteger.Parse() and CLng()

From my understanding, the string just needs to have all numerical values (and same for BigInteger.Parse()), so you don’t necessarily need to use a regex.

CLng(integerstring.Trim) would work if it is all numbers.
Typically, though one must check if it’s a number or it will throw an error.

If( IsNumeric(integerstring.Trim), CLng(integerstring.Trim), 0 )

So you can use 0 if the value coming in is wrong. But you can also use Regex, like you pointed out, if you want to extract only the number out from a alpha-numerica string. — depends on the goals of the project I suppose.

Thanks for pointing that out!

1 Like