Skip to content
Related Articles

Related Articles

Improve Article

JavaScript | BigInt.prototype.toLocaleString() Method

  • Last Updated : 02 Apr, 2020

The BigInt.prototype.toLocaleString() method is an inbuilt method in JavaScript which is used to return a string with a language-sensitive representation of this BigInt.

Syntax:

bigIntObj.toLocaleString(locales, options)

Parameters: This method accept two parameters as mentioned above and described below:

  • locales: This parameter holds the value of locale.
  • options: It is an optional parameter.

Return value: This method returns a string with a language-sensitive representation of the given BigInt.

Below examples illustrate the BigInt.prototype.toLocaleString() method in JavaScript:



Example 1:




let geekvar = 45334n;
console.log(geekvar.toLocaleString());
  
geekvar =78753456789123456789n;
console.log(geekvar.toLocaleString('de-DE'));
console.log(geekvar.toLocaleString('de-DE',
    { style: 'currency', currency: 'EUR' }));
console.log(geekvar.toLocaleString('hi'));

Output:

"45, 334"
"78.753.456.789.123.456.789"
"78.753.456.789.123.456.789, 00 €"
"7, 87, 53, 45, 67, 89, 12, 34, 56, 789"

Example 2:




let geekvar =78753456789123456789n;
  
console.log(geekvar.toLocaleString('ar-EG'));
console.log(geekvar.toLocaleString('en-IN',
        { maximumSignificantDigits: 3 }));
console.log(geekvar.toLocaleString('zh-Hans-CN-u-nu-hanidec'));
console.log(geekvar.toLocaleString(['ban', 'id']));

Output:

Supported Browsers: The browsers supported by BigInt.prototype.toLocaleString() method are listed below:

  • Google Chrome
  • Firefox
  • Opera
  • Safari
  • Edge
My Personal Notes arrow_drop_up
Recommended Articles
Page :