Lex V
Lex V

Reputation: 1447

Covert a long string to number

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

Answers (2)

Thomas Timbul
Thomas Timbul

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

Ahmed Muhammed  Elsaid
Ahmed Muhammed Elsaid

Reputation: 190

using built-in (BigInt or Number)

const bigNum= BigInt(//number)
const bigNum= Number(//number)

Upvotes: 0

Related Questions