Open In App

JavaScript BigInt toLocaleString() Method

Last Updated : 16 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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

Syntax:

bigIntObj.toLocaleString(locales, options)

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

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

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

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

Example 1: This example shows the use of the BigInt.prototype.toLocaleString() method in JavaScript.

javascript




<script>
    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'));
</script>


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: This example shows the use of the BigInt.prototype.toLocaleString() method in JavaScript.

javascript




<script>
    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']));
</script>


Output:

"٧٨٬٧٥٣٬٤٥٦٬٧٨٩٬١٢٣٬٤٥٦٬٧٨٩"
"7,88,00,00,00,00,00,00,00,000"
"七八,七五三,四五六,七八九,一二三,四五六,七八九"
"78.753.456.789.123.456.789"

We have a complete list of Javascript BigInt Methods, to check those please go through the Javascript BigInt Complete Reference article.

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

  • Google Chrome 67 and above
  • Edge 79 and above
  • Firefox 68 and above
  • Opera 54 and above
  • Safari 14 and above


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads