Question

15955067621307336078.toString(36); returns '3d7vzfy5k2as8' in Javascript because the large integer cannot be represented (the correct answer is '3d7vzfy5k29ou').

Does someone have a clever function that takes a large integer as a string and converts it to base 36?

Was it helpful?

Solution

Use this BigInt class, which allows conversion of arbitrarily large integers to any arbitrary base between 2 and 95. Use the bigInt2str() method to perform the conversion.

OTHER TIPS

For anyone curious, today we are using https://github.com/MikeMcl/bignumber.js instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top