All:
How can I correctly turn a VERY VERY LARGE number(at least 32 digits) into a character array?
For example:
var n = 111111122222233333334444444445555555555666666677777777788888888888
Thanks,
If you're dealing with very large numbers in javascript (anything greater than Number.MAX_SAFE_INTEGER) you'll have to handle the number differently than you would a normal integer.
Several libraries exist to help aid in this, all of which basically treat the number as a different type - such as a string - and provide custom methods for doing various operations and calculations.
For example, if you only need integers you can use BigInteger.js. Here's an implementation below:
const bigInt = require("big-integer")
const largeNumber = bigInt(
"111111122222233333334444444445555555555666666677777777788888888888",
)
const largeNumberArray = largeNumber.toString().split('')
Also check out some other stackoverflow questions and resources regarding handling big numbers in Javascript:
npm's big-number-> https://www.npmjs.com/package/big-number
What is the standard solution in JavaScript for handling big numbers (BigNum)?
Extremely large numbers in javascript
What is the standard solution in JavaScript for handling big numbers (BigNum)?
Number.MAX_SAFE_INTEGER- note: in Chrome and Node you canvar n = 111111122222233333334444444445555555555666666677777777788888888888n; n.toString().split('')- not the n at the end of the number