Reputation: 1447
Want to convert a string to a number. I tried Number(), parseInt() but the result is like, if the string is "586486785469547948790470945870879003409" the result is => 5.8648678546954796e+38 How to covert is as a number without using mathematical notations
Upvotes: 2
Views: 420
Reputation: 1733
use the built in BigInt
type:
const hugeBin = BigInt("586486785469547948790470945870879003409");
see also https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt
BigInt
is supported in all modern browsers, such as Chrome 67+, Edge 79+, Firefox 68+, Safari 14+ (see link above for more).
Support in NodeJS was added in version 10.4.0.
Upvotes: 2
Reputation: 190
using built-in (BigInt or Number)
const bigNum= BigInt(//number)
const bigNum= Number(//number)
Upvotes: 0