Javascript BigInt toLocaleString()

Introduction

The Javascript BigInt toLocaleString() method returns a string for big integer.

It can represent a big int in a language-sensitive way.

bigIntObj.toLocaleString([locales [, options]])
Parameter Meaning
locales Locale to use to format the BigInt
options Options to format the BigInt
var bigint = 3500n;

let a = bigint.toLocaleString();
console.log(a);//from  w  w w .j a va 2 s .  c  o m

Using locales

var bigint = 123456789123456789n;

console.log(bigint.toLocaleString('de-DE'));
console.log(bigint.toLocaleString('ar-EG'));
console.log(bigint.toLocaleString('en-IN'));

Using options

The toLocaleString() can be customized using the options argument:

var bigint = 123456789123456789n;

console.log(bigint.toLocaleString('de-DE', { style: 'currency', currency: 'EUR' }));
console.log(bigint.toLocaleString('ja-JP', { style: 'currency', currency: 'JPY' }))
console.log(bigint.toLocaleString('en-IN', { maximumSignificantDigits: 3 }));



PreviousNext

Related