diff options
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/bigint/tolocalestring/index.html')
-rw-r--r-- | files/zh-cn/web/javascript/reference/global_objects/bigint/tolocalestring/index.html | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/bigint/tolocalestring/index.html b/files/zh-cn/web/javascript/reference/global_objects/bigint/tolocalestring/index.html new file mode 100644 index 0000000000..434bceb0d9 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/bigint/tolocalestring/index.html @@ -0,0 +1,116 @@ +--- +title: BigInt.prototype.toLocaleString() +slug: Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString +translation_of: Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString +--- +<div>{{JSRef}}</div> + +<p><strong><code>toLocaleString()</code></strong> 方法返回一个字符串,该字符串具有此 <code>BigInt</code> 的 language-sensitive 表达形式。</p> + +<div>{{EmbedInteractiveExample("pages/js/bigint-tolocalestring.html")}}</div> + + + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"><code><em>bigIntObj</em>.toLocaleString(</code><code>[locales [, options]])</code></pre> + +<h3 id="参数">参数</h3> + +<p><code>locales</code> 和 <code>options</code> 参数可自定义函数的行为,并允许应用程序指定应使用其格式约定的语言。在忽略 <code>locales</code> 和 <code>options</code> 参数的实现中,使用的 <code>locale</code> 和返回的字符串形式完全依赖于实现。</p> + +<div>{{page('/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat', '参数')}}</div> + +<h3 id="返回值">返回值</h3> + +<p>具有此 <code>BigInt</code> 的 language-sensitive 表示形式的字符串。</p> + +<h2 id="例子">例子</h2> + +<h3 id="Using_toLocaleString">Using <code>toLocaleString</code></h3> + +<p>在不指定语言环境的基本用法中,将返回默认语言环境中带默认选项的格式化字符串。</p> + +<pre class="brush: js">var bigint = 3500n; + +bigint.toLocaleString(); +// Displays "3,500" if in U.S. English locale +</pre> + +<h3 id="Using_locales">Using <code>locales</code></h3> + +<p>这个例子展示了本地化数字格式的一些变体。为了获得应用程序用户界面中使用的语言的格式,请确保使用 <code>locales</code> 参数指定该语言(可能还有一些备用语言):</p> + +<pre class="brush: js">var bigint = 123456789123456789n; + +// German uses period for thousands +console.log(bigint.toLocaleString('de-DE')); +// → 123.456.789.123.456.789 + +// Arabic in most Arabic speaking countries uses <a href="https://en.wikipedia.org/wiki/Eastern_Arabic_numerals">Eastern Arabic</a> digits +console.log(bigint.toLocaleString('ar-EG')); +// → ١٢٣٬٤٥٦٬٧٨٩٬١٢٣٬٤٥٦٬٧٨٩ + +// India uses thousands/lakh/crore separators +console.log(bigint.toLocaleString('en-IN')); +// → 1,23,45,67,89,12,34,56,789 + +// the nu extension key requests a numbering system, e.g. Chinese decimal +console.log(bigint.toLocaleString('zh-Hans-CN-u-nu-hanidec')); +// → 一二三,四五六,七八九,一二三,四五六,七八九 + +// when requesting a language that may not be supported, such as +// Balinese, include a fallback language, in this case Indonesian +console.log(bigint.toLocaleString(['ban', 'id'])); +// → 123.456.789.123.456.789 +</pre> + +<h3 id="Using_options">Using <code>options</code></h3> + +<p><code>toLocaleString</code> 提供的结果可以使用 <code>options</code> 参数进行自定义:</p> + +<pre class="brush: js">var bigint = 123456789123456789n; + +// request a currency format +console.log(bigint.toLocaleString('de-DE', { style: 'currency', currency: 'EUR' })); +// → 123.456.789.123.456.789,00 € + +// the Japanese yen doesn't use a minor unit +console.log(bigint.toLocaleString('ja-JP', { style: 'currency', currency: 'JPY' })) +// → ¥123,456,789,123,456,789 + +// limit to three significant digits +console.log(bigint.toLocaleString('en-IN', { maximumSignificantDigits: 3 })); +// → 1,23,00,00,00,00,00,00,000 +</pre> + +<h2 id="性能">性能</h2> + +<p>格式化大量数字时,最好创建 {{jsxref("NumberFormat")}} 对象并使用其 {{jsxref("NumberFormat.format")}} 属性提供的函数。</p> + +<h2 id="标准">标准</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + </tr> + <tr> + <td><a href="https://tc39.es/ecma402/#sup-bigint.prototype.tolocalestring">BigInt</a></td> + <td>Stage 3</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器支持">浏览器支持</h2> + +<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p> + +<p>{{Compat("javascript.builtins.BigInt.toLocaleString")}}</p> + +<h2 id="请参阅">请参阅</h2> + +<ul> + <li>{{jsxref("BigInt.toString()")}}</li> +</ul> |