How to Convert a JavaScript BigInt Value to a String?

JavaScript BigInt to String Conversion

You can convert a bigint to a string by using the String wrapper object or the BigInt.prototype.toString() method like so:

// ES10+
const MAX_SAFE_INTEGER = 9007199254740991n;

console.log(String(MAX_SAFE_INTEGER)); // '9007199254740991'
console.log(MAX_SAFE_INTEGER.toString()); // '9007199254740991'

You may also use the BigInt.prototype.toLocaleString() method if you wish to output the bigint value as a formatted string based on a specific locale. For example:

// ''

console.log(MAX_SAFE_INTEGER.toLocaleString('de-DE', { style: 'currency', currency: 'EUR' }));
// ' €'

Hope you found this post useful. It was published . Please show your love and support by sharing this post.