Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Convert long strings to big numbers

Lets say we want to Convert/Parse following string

string mystring = "221021290110000123452229211210282900128222900"

to an number

Of what type would this number be?

i tested Double.TryParse(mystring,out myBigNumber) but i got an E+ number which i can't use for my mathematical operations because the modulo operation will result in a wrong number

like image 367
WiiMaxx Avatar asked Jun 13 '13 13:06

WiiMaxx


People also ask

How to transform a string into a number?

You convert a string to a number by calling the Parse or TryParse method found on numeric types ( int , long , double , and so on), or by using methods in the System. Convert class. It's slightly more efficient and straightforward to call a TryParse method (for example, int.

What is the fastest way to convert a string to a number?

Use the parseInt() function to convert a string to a number, e.g. const num1 = parseInt(str) . To extract a number from a string in TypeScript, call the replace() method, e.g. str.


2 Answers

var bigNumber = BigInteger.Parse(mystring);

See BigInteger.Parse.

As far as I know BigInteger is limited by the amount of memory you have available.

like image 177
Dustin Kingen Avatar answered Sep 28 '22 02:09

Dustin Kingen


BigInteger is what you are looking for

like image 30
Mzf Avatar answered Sep 28 '22 00:09

Mzf