# How to convert long string to number?

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

thanks

Hi,

CLng(integerstring.Trim)
or
Convert.ToLong(integerstring.Trim)

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:

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

or replace the Alphas
CLng(System.Text.RegularExpressions.Regex.Replace(text, â€ś[^0-9]â€ť, â€śâ€ť))

Thankyoo

2 Likes

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

1 Like

Try BigInteger

3 Likes

BigInteger solved the problem thanks

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

Regards,
Ganesh

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â€¦

Ganesh

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

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.

Regards
Balamurugan

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

I meant, I didnâ€™t know if there was a difference between using BigInteger.Parse() and CLng()

Hi,
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